sisau
Mechanical
- Mar 5, 2010
- 19
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! ;-)
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
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! ;-)
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