Hide Table of Contents

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

 



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) 2012 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.