Hide Table of Contents

Get Mass Properties of Assembly Component Example (VBA)

An assembly component (part or sub-assembly) can contain assembly-level features, typically cuts. These features affect the mass properties, but the features are not present in the part or sub-assembly.

This example shows to get the mass properties of an assembly component.

 

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

' Preconditions:

'       (1) Assembly is open.

'       (2) Component is selected.

'

' Postconditions: None

'

' Notes: The mass property values are returned relative to

'        the component origin, not the assembly origin.

'

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

Option Explicit

Public Enum swMassPropertiesStatus_e

    swMassPropertiesStatus_OK = 0

    swMassPropertiesStatus_UnknownError = 1

    swMassPropertiesStatus_NoBody = 2

End Enum

Public Enum swUserPreferenceDoubleValue_e

    swMaterialPropertyDensity = 7

End Enum

Sub main()

    Dim swApp                   As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swSelMgr                As SldWorks.SelectionMgr

    Dim swComp                  As SldWorks.Component2

    Dim swCompModel             As SldWorks.ModelDoc2

    Dim swCompBody              As SldWorks.body2

    Dim vMassProps              As Variant

    Dim nDensity                As Double

    Dim bRet                    As Boolean

    

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swSelMgr = swModel.SelectionManager

    Set swComp = swSelMgr.GetSelectedObjectsComponent2(1)

    

    Set swCompBody = swComp.GetBody

    

    Set swCompModel = swComp.GetModelDoc

    

    ' Calculate component material density

    nDensity = swCompModel.GetUserPreferenceDoubleValue(swMaterialPropertyDensity)

    

    ' Use this method to get component mass properties

    vMassProps = swCompBody.GetMassProperties(nDensity)

    

    Debug.Print "File = " & swModel.GetPathName

    Debug.Print "  Comp     = " & swComp.Name2

    Debug.Print "  Config   = " & swComp.ReferencedConfiguration

    Debug.Print "  Density  = " & nDensity & " kg/m^3"

    Debug.Print ""

    Debug.Print "  CenterOfMass = (" & vMassProps(0) * 1000# & ", " & vMassProps(1) * 1000# & ", " & vMassProps(2) * 1000# & ") mm"

    Debug.Print "  Volume       = " & vMassProps(3) * 1000000000# & " mm^3"

    Debug.Print "  Area         = " & vMassProps(4) * 1000000# & " mm^2"

    Debug.Print "  Mass         = " & vMassProps(5) & " kg"

    Debug.Print "  MomXX        = " & vMassProps(6) & " kg*m^2"

    Debug.Print "  MomYY        = " & vMassProps(7) & " kg*m^2"

    Debug.Print "  MomZZ        = " & vMassProps(8) & " kg*m^2"

    Debug.Print "  MomXY        = " & vMassProps(9) & " kg*m^2"

    Debug.Print "  MomZX        = " & vMassProps(10) & " kg*m^2"

    Debug.Print "  MomYZ        = " & vMassProps(11) & " kg*m^2"

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:   Get Mass Properties of Assembly Component 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) 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.