Hide Table of Contents

SOLIDWORKS API Help

Add Multibody Part Explode Step Example (VBA)

This example shows how to create an explode view of a multibody part.

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

' Preconditions:

' 1. Open public_documents\samples\tutorial\multibody\multi_Inter.sldprt.

' 2. Open an Immediate window.

'

' Postconditions:

' 1. Creates Exploded View1 in ConfigurationManager.

' 2. Adds Chain1 to Exploded View1.

' 3. Displays the Exploded View1 in its exploded state.

' 4. Inspect the Immediate window, the ConfigurationManager,

'    and the graphics area.

'

' Note: Because the model is used elsewhere, do not save any changes.

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

 

Option Explicit

 

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.PartDoc

Dim config As SldWorks.Configuration

Dim configName As String

Dim swMdl As SldWorks.ModelDoc2

Dim explStep As SldWorks.PartExplodeStep

Dim comp As SldWorks.Body2

Dim var As Variant

Dim varViews As Variant

Dim configVar As Variant

Dim boolstatus As Boolean

Dim i As Long

Dim errCode As Long

   

 

Sub main()

 

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swMdl = swModel

    configVar = swMdl.GetConfigurationNames

 

    Call swModel.CreateExplodedView

    varViews = swModel.GetExplodedViewNames(configVar(0))

    configName = swModel.GetExplodedViewConfigurationName(varViews(0))

    Set config = swMdl.GetConfigurationByName(configName)

   

    swModel.ShowExploded True, varViews(0)

   

    'Select the bodies to move

    boolstatus = swModel.Extension.SelectByID2("Extrude-Thin1", "SOLIDBODY", 0, 0, 0, True, 1, Nothing, 0)

 

    'Add an explode step without selecting an explode direction entity

    'Defaults to the Z-direction manipulator index

    Set explStep = config.AddPartExplodeStep("Exploded View1", 0.07, -1, False, True, errCode)

   

    Call swMdl.EditRebuild3

   

    'Get bodies moved in the explode step

    var = explStep.GetBodies()

   

    Debug.Print "Explode view: " & varViews(0)

    Debug.Print "Explode step: " & explStep.Name

    Debug.Print "Explode distance (m): " & explStep.ExplodeDistance

    Debug.Print "Reverse translation direction? " & explStep.ReverseTranslationDirection

    Debug.Print "Automatically space components on drag? " & explStep.AutoSpaceBodiesOnDrag

   

     Debug.Print "Bodies moved in the explode step:"

    For i = 0 To UBound(var)

        Set comp = var(i)

        Debug.Print "  " & comp.Name

    Next

 

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:   Add Multibody Part Explode Step 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) 2021 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.