Hide Table of Contents

SOLIDWORKS API Help

Create Save Bodies Feature and Create an Assembly Example (VBA)

This example shows how to create a save bodies feature, create part documents with the save bodies, and create an assembly with the parts.

 

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

' Preconditions:

' 1. Part document is open and contains a feature split of two.

' 2. The Solid Bodies folder contains Split1[1] and Split2[2].

' 3. C:\temp\SaveBodies exists.

'

' Postconditions:

' 1. C:\temp\SaveBodies\1.sldprt, C:\temp\SaveBodies\2.sldprt,

'    and C:\temp\assem.sldasm are created.

' 2. In the original part, the Split1 solid bodies in the

'    Solid Bodies folder became a Save Bodies1 feature.

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

 

Option Explicit

  

Dim swApp As SldWorks.SldWorks

 

Dim swModel As SldWorks.ModelDoc2

 

Dim swSelMgr As SldWorks.SelectionMgr

 

Dim swFeat As SldWorks.Feature

 

Dim swFeatMgr As SldWorks.FeatureManager

 

Dim swBodyFolder As SldWorks.BodyFolder

 

Dim v1 As Variant

 

Dim i As Long

 

Dim fileNames(1) As String

 

Dim fileNameVar As Variant

 

 

 

Sub GetVariantOfBody(swFeature As SldWorks.Feature, bodyList As Variant)

 

    Dim tt As Variant

 

   

    Set swBodyFolder = swFeature.GetSpecificFeature2

 

    Dim count As Integer

 

    count = swBodyFolder.GetBodyCount

 

    If (count < 1) Then

 

        MsgBox ("There are no bodies. Please create a body.")

 

    Else

 

        bodyList = swBodyFolder.GetBodies

 

    End If

 

End Sub

 

 

Sub main()

 

 

 

    Set swApp = Application.SldWorks

   

    Set swModel = swApp.ActiveDoc

   

    Set swSelMgr = swModel.SelectionManager

   

    Set swFeat = swModel.FirstFeature

   

    Set swFeatMgr = swModel.FeatureManager

   

    

   

    Dim contLoop As Boolean

   

    contLoop = True

   

    While Not swFeat Is Nothing And contLoop = True

   

        Dim Name As String

   

        Name = swFeat.GetTypeName2

   

       

        If (Name = "SolidBodyFolder") Then

   

           

            GetVariantOfBody swFeat, v1

   

            contLoop = False

   

        End If

   

        If (contLoop = True) Then

   

            Set swFeat = swFeat.GetNextFeature

   

        End If

   

    Wend

   

    

   

    fileNames(0) = "C:\temp\SaveBodies\1.sldprt"

    fileNames(1) = "C:\temp\SaveBodies\2.sldprt"

   

   

    fileNameVar = fileNames

   

    swFeatMgr.CreateSaveBodyFeature v1, fileNameVar, "c:\temp\assem.sldasm", -1, -1

 

 

 

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:   Create Save Bodies Feature and Create an Assembly 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) 2020 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.