Hide Table of Contents

Get Mass Properties of Multibody Assembly Component Example (VBA)

This example shows how to get the mass properties of a multibody assembly component.

 

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

'

' Problem: An assembly component (part or subassembly) may contain

'       assembly-level features, typically a cut. This will

'       obviously affect the mass properties but the feature

'       will not be present in the part or subassembly.

'

' Preconditions:

'       (1) An assembly is open.

'       (2) A multibody component is selected.

'

' Postconditions: None

'

' NOTE: The mass property values returned are relative to

'       the component origin, not the assembly origin

'

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

Option Explicit

Public Enum swMassPropertyMoment_e

    swMassPropertyMomentAboutCenterOfMass = 0

    swMassPropertyMomentAboutCoordSys = 1

End Enum

Public Enum swMassPropertiesStatus_e

    swMassPropertiesStatus_OK = 0

    swMassPropertiesStatus_UnknownError = 1

    swMassPropertiesStatus_NoBody = 2

End Enum

Public Enum swBodyType_e

    swSolidBody = 0

    swSheetBody = 1

    swWireBody = 2

    swMinimumBody = 3

    swGeneralBody = 4

    swEmptyBody = 5

End Enum

Public Enum swUserPreferenceDoubleValue_e

    swMaterialPropertyDensity = 7

End Enum

Sub main()

    Dim swApp                   As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swDocExt                As SldWorks.ModelDocExtension

    Dim swMass                  As SldWorks.MassProperty

    Dim swSelMgr                As SldWorks.SelectionMgr

    Dim swComp                  As SldWorks.Component2

    Dim vBodyArr                As Variant

    Dim vCoM                    As Variant

    Dim vMoI                    As Variant

    Dim vPrinAoIx               As Variant

    Dim vPrinAoIy               As Variant

    Dim vPrinAoIz               As Variant

    Dim vPrinMoI                As Variant

    Dim nDensity                As Double

    Dim bRet                    As Boolean

    

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swDocExt = swModel.Extension

    Set swMass = swDocExt.CreateMassProperty

    Set swSelMgr = swModel.SelectionManager

    Set swComp = swSelMgr.GetSelectedObjectsComponent2(1)

    

    vBodyArr = swComp.GetBodies2(swSolidBody): Debug.Assert Not IsEmpty(vBodyArr)

    

    bRet = swMass.AddBodies((vBodyArr)): Debug.Assert bRet

    

    vCoM = swMass.CenterOfMass

    vMoI = swMass.GetMomentOfInertia(swMassPropertyMomentAboutCenterOfMass)

    vPrinAoIx = swMass.PrincipleAxesOfInertia(0)

    vPrinAoIy = swMass.PrincipleAxesOfInertia(1)

    vPrinAoIz = swMass.PrincipleAxesOfInertia(2)

    vPrinMoI = swMass.PrincipleMomentsOfInertia

    

    Debug.Print "File = " & swModel.GetPathName

    Debug.Print "  Comp         = " & swComp.Name2

    Debug.Print "  Config       = " & swComp.ReferencedConfiguration

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

    Debug.Print ""

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

    Debug.Print "  Volume       = " & swMass.Volume * 1000000000# & " mm^3"

    Debug.Print "  Area         = " & swMass.SurfaceArea * 1000000# & " mm^2"

    Debug.Print "  Mass         = " & swMass.Mass & " kg"

    Debug.Print ""

    Debug.Print "  Ix           = (" & vPrinAoIx(0) & ", " & vPrinAoIx(1) & ", " & vPrinAoIx(2) & ")"

    Debug.Print "  Iy           = (" & vPrinAoIy(0) & ", " & vPrinAoIy(1) & ", " & vPrinAoIy(2) & ")"

    Debug.Print "  Iz           = (" & vPrinAoIz(0) & ", " & vPrinAoIz(1) & ", " & vPrinAoIz(2) & ")"

    Debug.Print ""

    Debug.Print "  Px           = " & vPrinMoI(0) & " kg*m^2"

    Debug.Print "  Py           = " & vPrinMoI(1) & " kg*m^2"

    Debug.Print "  Pz           = " & vPrinMoI(2) & " kg*m^2"

    Debug.Print ""

    Debug.Print "  Lxx          = " & vMoI(0) & " kg*m^2"

    Debug.Print "  Lxy          = " & vMoI(1) & " kg*m^2"

    Debug.Print "  Lxz          = " & vMoI(2) & " kg*m^2"

    Debug.Print "  Lyx          = " & vMoI(3) & " kg*m^2"

    Debug.Print "  Lyy          = " & vMoI(4) & " kg*m^2"

    Debug.Print "  Lyz          = " & vMoI(5) & " kg*m^2"

    Debug.Print "  Lzx          = " & vMoI(6) & " kg*m^2"

    Debug.Print "  Lzy          = " & vMoI(7) & " kg*m^2"

    Debug.Print "  Lzz          = " & vMoI(8) & " 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 Multibody 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.