Hide Table of Contents

Get Bodies in Components Example (VB.NET)

This example shows how to get the number of normal and user bodies in the components in an assembly.

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

' Preconditions:

' 1. Specified assembly document exists.

' 2. Run the macro.

'

' Postconditions: Each component's name, number of

' solid bodies, body names, and body types are

' printed to the Immediate window.

'

' To understand the results of the macro:

' 1. Right-click filterholder in the FeatureManager

'    design tree and click the Open Part button in

'    the context toolbar. Notice that there

'    are no screw holes in the part.

' 2. Close the part and examine the filterholder

'    component, which is the orange, flat, circular

'    component located on the front of the assembly,

'    in the graphics area. There are screw

'    holes in the component.

' 3. Locate filterholder's information in the

'    Immediate window. Because the component was

'    modified in the assembly, its body is identified

'    as a user body.

'

' NOTE: Because this assembly document is used by

'       a SolidWorks online tutorial, do not save

'       any changes when closing the document.

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

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Imports System

Imports System.Diagnostics

 

Partial Class SolidWorksMacro

 

    Public Sub main()

 

        Dim swModel As ModelDoc2

        Dim swAssembly As AssemblyDoc

        Dim vComponents As Object

        Dim oneComponent As Component2

        Dim vBodies As Object

        Dim vBodyInfo As Object = Nothing

        Dim BodyType As Integer

        Dim errors As Integer, warnings As Integer

        Dim i As Integer, j As Integer

 

        ' Open the assembly; substitute the name of your assembly here

        swModel = swApp.OpenDoc6("C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\toolbox\lens_mount.sldasm", swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)

        swAssembly = swModel

 

        ' Get the components in the assembly

        vComponents = swAssembly.GetComponents(True)

        For i = 0 To UBound(vComponents)

            oneComponent = vComponents(i)

            Debug.Print(" ")

            Debug.Print("Component name: " & oneComponent.Name2)

            ' Get the solid bodies in the component

            vBodies = oneComponent.GetBodies3(swBodyType_e.swSolidBody, vBodyInfo)

            Debug.Print("  Number of solid bodies: " & (UBound(vBodies) + 1))

            For j = 0 To UBound(vBodies)

                Debug.Print("  Body number: " & (j + 1))

                Debug.Print("  Body name: " & vBodies(j).Name)

                ' Print the type of body

                BodyType = vBodyInfo(j)

                Select Case BodyType

                    Case 0

                        Debug.Print("  Body type: user")

                    Case 1

                        Debug.Print("  Body type: normal")

                End Select

            Next

        Next

    End Sub

 

    ''' <summary>

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

    ''' </summary>

    Public swApp As SldWorks

 

End Class



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:   Get Bodies in Components Example (VB.NET)
*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.