Hide Table of Contents

Change Imported File Associated with an Imported Feature Example (VBA)

This example shows how to change the imported file associated with an imported feature.

 

'--------------------------------

'

' Preconditions:

'         (1) Model document is open and contains an imported feature.

'         (2) Imported feature is selected.

'         (3) The file C:\samples\case2.x_t exists.

'

' Postconditions: Selected imported feature is replaced by the specified

'         imported file, case2.x_t.

'

'---------------------------------

Option Explicit

Public Enum swBodyType_e

    swSolidBody = 0

    swSheetBody = 1

    swWireBody = 2

    swMinimumBody = 3

    swGeneralBody = 4

    swEmptyBody = 5

End Enum

Sub main()

    Const sImportFileName           As String = "C:\samples\case2.x_t"

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swSelMgr                    As SldWorks.SelectionMgr

    Dim swFeat                      As SldWorks.feature

    Dim swNewModel                  As SldWorks.ModelDoc2

    Dim swNewPart                   As SldWorks.PartDoc

    Dim vBodyArr                    As Variant

    Dim swBody                      As SldWorks.body2

    Dim swTempBody                  As SldWorks.body2

    Dim bRet                        As Boolean

    

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swSelMgr = swModel.SelectionManager

    Set swFeat = swSelMgr.GetSelectedObject5(1)

    Debug.Print "File = " & swModel.GetPathName

    Debug.Print "  Feat = " & swFeat.Name

    Debug.Print "    FeatTypeName = " & swFeat.GetTypeName

    

    ' Open import file into a new part file

    bRet = swApp.LoadFile2(sImportFileName, ""): Debug.Assert bRet

    

    Set swNewModel = swApp.ActiveDoc

    Set swNewPart = swNewModel

    

    ' Only consider solid bodies

    vBodyArr = swNewPart.GetBodies2(swSolidBody, True)

    Debug.Assert Not IsEmpty(vBodyArr)

    Debug.Assert 0 = UBound(vBodyArr)

    

    ' Only consider first solid body

    Set swBody = vBodyArr(0)

    Set swTempBody = swBody.Copy

    

    bRet = swFeat.SetBody2(swTempBody, False): Debug.Assert bRet

    

    ' Close SolidWorks file associated with opening the import file

    swApp.QuitDoc swNewModel.GetTitle

    

    bRet = swModel.ForceRebuild3(False): Debug.Assert bRet

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:   Change Imported File Associated with an Imported Feature 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) 2010 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.