Import Models as Solids
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 affect.
'---------------------------------------
'
' Preconditions:
' (1)
Substitute the file named xyz.stp with the
' name
of the file that you want to import.
' (2)
The macro is located in the same folder as the file
' that
you want to import.
'
' Postconditions: Your file is imported into SolidWorks
' and
solids are formed if possible.
'
'-----------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Sub main()
Dim
rtn As Boolean
Dim
retval As Long
Dim
pathname As String
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.LoadFile3 pathname + "xyz.stp",
"r", Nothing
'
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.LoadFile3 pathname + "xyz.stp",
"r", Nothing
End Sub