×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

CoordinateSystem / Macro / VisualBasic / SW / MassProperties

CoordinateSystem / Macro / VisualBasic / SW / MassProperties

CoordinateSystem / Macro / VisualBasic / SW / MassProperties

(OP)
hey!

i have written a macro to get the mass properties of the different parts of a solidworks assembly on an excel sheet. the problem i have is that i get all this properties according to the default coordinate system.

i have checked the API help but i am a beginner in this field and i can't find a solution.

i show you the macro i was using (only for the part LowerArm-1) so if you know what should i add to my macro, please let me know it! winky smile

Sub massdata()
    Dim swApp                   As Object
    Dim swModel                 As Object
    Dim swDocExt                As Object
    Dim swMass                  As Object
    Dim swSelMgr                As Object
    Dim swComp                  As Object
    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    
    Dim Part                    As Object    
    Dim boolstatus              As Boolean

    Set swApp = CreateObject("SldWorks.Application")    
    Set Part = swApp.ActiveDoc    
    boolstatus = Part.Extension.SelectByID2("LowerArm-1@Assem4", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

    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

RE: CoordinateSystem / Macro / VisualBasic / SW / MassProperties

Look for "Get Excel Cell Value for Density Example (VB6)" under API help. This is reverse of what you need.

Deepak Gupta
SW2009 SP4.1
SW2007 SP5.0
MathCAD 14.0

RE: CoordinateSystem / Macro / VisualBasic / SW / MassProperties

(OP)
i think you didn't understand what i meant... probably the explanation of my problem was not as good as it should be.

i do:
insert > reference geometry > coordinate system

then i want to get the mass properties according to this coordinate systems.

in the API help i have found MassProperty.SetCoordinateSystem but i don't know what i have to write on visual basic to use it

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources