Hide Table of Contents

Import Models as Solids Example (VBA)

This example shows how to set the options to import non-native SOLIDWORKS models into SOLIDWORKS as solids.

NOTE: You must set the values of both swUserPreferenceIntegerValue_e.swCreateBodyFromSurfaces and swUserPreferenceIntegerValue_e.swImportUseBrep for swUserPreferenceIntegerValue_e.swImportUseBrep to have an effect.

'----------------------------------------------------
' Preconditions:
' 1. Substitute the file_to_import.STEP with the
'    name of the STEP file that you want to import.
' 2. Copy the STEP file to this macro's folder.
'
' Postconditions:
' 1. Loads the file into a new document
'    and forms solids, if possible, but does
'    not directly map topologies using BREP data.
' 2. Loads the file into a new document
'    and forms solids, if possible, and
'    directly maps topologies using BREP data.
' 3. Examine both documents. Switch documents
'    by clicking Window and clicking the document to view.
' 4. Examine the FeatureManager design tree and
'    the graphics area in each document.
'-----------------------------------------------------
Option Explicit
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swImportStepData As SldWorks.ImportStepData
    Dim rtn As Boolean
    Dim retval As Long
    Dim pathname As String
    Dim errors As Long
    Set swApp = Application.SldWorks
    pathname = swApp.GetCurrentMacroPathName
    pathname = Left(pathname, InStrRev(pathname, "\"))
    ' Get swImportUseBrep value
    retval = swApp.GetUserPreferenceIntegerValue(swImportUseBrep)
    ' Set swImportUseBrep value to 1 (Do not import the model
    ' by directly mapping topologies using BREP data)
    ' Let SOLIDWORKS attempt to knit the surfaces into solids
    rtn = swApp.SetUserPreferenceIntegerValue(swImportUseBrep, 1)
    ' Set swCreateBodyFromSurfacesOption to swGeneralImportbyBrep
    rtn = swApp.SetUserPreferenceIntegerValue(SwConst.swUserPreferenceIntegerValue_e.swCreateBodyFromSurfacesOption, SwConst.swGeneralImportByBrep)
    ' Load the STEP file
    swApp.LoadFile4 pathname + "file_to_import.STEP", "r", swImportStepData, errors
   ' Set swImportUseBrep value to 0 (Import the model by directly mapping
   ' topologies using BREP data)
   ' Attempt to import the model by directly mapping topologies
   ' using boundary representation (BREP) data.
    rtn = swApp.SetUserPreferenceIntegerValue(swImportUseBrep, 0)
    ' Get swImportUseBrep value
    retval = swApp.GetUserPreferenceIntegerValue(swImportUseBrep)
    ' Load the STEP file
    swApp.LoadFile4 pathname + "file_to_import.STEP", "r", swImportStepData, errors
End Sub
 


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Import Models as Solids Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2018 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.