Hide Table of Contents

SOLIDWORKS API Help

Add Multibody Part Explode Step Example (C#)

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.

// ----------------------------------------------------------------------------

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System.Runtime.InteropServices;

using System.Diagnostics;

 

 

namespace MultibodyPartExplode_CSharp

{

 

 

    partial class SolidWorksMacro

    {

        public void Main()

        {

            PartDoc swModel;

 

            Configuration config;

 

            string configName;

 

            ModelDoc2 swMdl;

 

            PartExplodeStep explStep;

 

            Body2 comp;

 

            object[] var;

 

            object[] varViews;

 

            object[] configVar;

 

            bool boolstatus;

 

            int i;

 

            int errCode;

 

            swModel = (PartDoc)swApp.ActiveDoc;

 

            swMdl = (ModelDoc2)swModel;

 

 

            configVar = (object[])swMdl.GetConfigurationNames();

 

 

            swModel.CreateExplodedView();

 

 

            varViews = (object[])swModel.GetExplodedViewNames((string)configVar[0]);

 

            configName = swModel.GetExplodedViewConfigurationName((string)varViews[0]);

 

            config = (Configuration)swMdl.GetConfigurationByName(configName);

 

 

            swModel.ShowExploded(true, (string)varViews[0]);

 

 

 

            // Select the bodies to move

 

            boolstatus = swMdl.Extension.SelectByID2("Extrude-Thin1", "SOLIDBODY", 0, 0, 0, true, 1, null, 0);

 

 

 

            // Add an explode step without selecting an explode direction entity

 

            // Defaults to the Z-direction manipulator index

 

            explStep = (PartExplodeStep)config.AddPartExplodeStep("Exploded View1", 0.07, -1, false, true, out errCode);

 

 

            swMdl.EditRebuild3();

 

 

            // Get bodies moved in the explode step

 

            var = (object[])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; i <= var.GetUpperBound(0); i++)

            {

                comp = (Body2)var[i];

 

                Debug.Print("  " + comp.Name);

            }

        }

 

 

        /// <summary>

        ///     ''' The SldWorks swApp variable is pre-assigned for you.

        ///     ''' </summary>

        public SldWorks swApp;

 

    }

}

 

 



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 (C#)
*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) 2023 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.