First part:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
m_invApp = GetObject(, "Inventor.Application")
' Set a reference to the part document.
' This assumes a part document is active.
Dim oAssyDoc As AssemblyDocument
oAssyDoc = m_invApp.ActiveDocument
' Set a reference to the mass properties object.
Dim oMassProps As MassProperties
oMassProps = oAssyDoc.ComponentDefinition.MassProperties
'Check if mass property results are already available
'at a high accuracy level or better. If so, simply
'print out the results, else, set a flag to not cache
'the results in the document.
If oMassProps.AvailableAccuracy = MassPropertiesAccuracyEnum.k_High And
oMassProps.AvailableAccuracy = MassPropertiesAccuracyEnum.k_VeryHigh Then
' Set the accuracy to high.
oMassProps.Accuracy = MassPropertiesAccuracyEnum.k_High
'Set CacheResultsOnCompute property to False
'so that results are not saved with the document
'and hence the document is not 'dirtied'.
oMassProps.CacheResultsOnCompute = False
End If
' Display the mass properties of the part.
Debug.Print("Area: " & oMassProps.Area)
ListBox1.Items.Add("Area: " & oMassProps.Area)
Debug.Print("Center of Mass: " & oMassProps.CenterOfMass.X & ", " & oMassProps.CenterOfMass.Y & ", " & oMassProps.CenterOfMass.Z)
ListBox1.Items.Add("Center of Mass: " & oMassProps.CenterOfMass.X & ", " & oMassProps.CenterOfMass.Y & ", " & oMassProps.CenterOfMass.Z)
ListBox1.Items.Add("")
Debug.Print("Mass: " & oMassProps.Mass)
ListBox1.Items.Add("Mass: " & oMassProps.Mass)
ListBox1.Items.Add("")
Dim adPrincipalMoments(0 To 3) As Double
Call oMassProps.PrincipalMomentsOfInertia(adPrincipalMoments(1),
adPrincipalMoments(2),
adPrincipalMoments(3))
Debug.Print("Principal Moments of Inertia: " & adPrincipalMoments(1) & ", " & adPrincipalMoments(2) & ", " & adPrincipalMoments(3))
ListBox1.Items.Add("Principal Moments of Inertia: " & adPrincipalMoments(1) & ", " & adPrincipalMoments(2) & ", " & adPrincipalMoments(3))
ListBox1.Items.Add("")
Dim adRadiusOfGyration(0 To 3) As Double
Call oMassProps.RadiusOfGyration(adRadiusOfGyration(1),
adRadiusOfGyration(2),
adRadiusOfGyration(3))
Debug.Print("Radius of Gyration: " & adRadiusOfGyration(1) & ", " & adRadiusOfGyration(2) & ", " & adRadiusOfGyration(3))
ListBox1.Items.Add("Radius of Gyration: " & adRadiusOfGyration(1) & ", " & adRadiusOfGyration(2) & ", " & adRadiusOfGyration(3))
ListBox1.Items.Add("")
Debug.Print("Volume: " & oMassProps.Volume)
ListBox1.Items.Add("Volume: " & oMassProps.Volume)
ListBox1.Items.Add("")
Dim Ixx As Double
Dim Iyy As Double
Dim Izz As Double
Dim Ixy As Double
Dim Iyz As Double
Dim Ixz As Double
Call oMassProps.XYZMomentsOfInertia(Ixx, Iyy, Izz, Ixy, Iyz, Ixz)
Debug.Print("Moments: ")
ListBox1.Items.Add("Moments: ")
Debug.Print(" Ixx: " & Ixx)
ListBox1.Items.Add(" Ixx: " & Ixx)
Debug.Print(" Iyy: " & Iyy)
ListBox1.Items.Add(" Iyy: " & Iyy)
Debug.Print(" Izz: " & Izz)
ListBox1.Items.Add(" Izz: " & Izz)
Debug.Print(" Ixy: " & Ixy)
ListBox1.Items.Add(" Ixy: " & Ixy)
Debug.Print(" Iyz: " & Iyz)
ListBox1.Items.Add(" Iyz: " & Iyz)
Debug.Print(" Ixz: " & Ixz)
ListBox1.Items.Add(" Ixz: " & Ixz)
End Sub
How could I measure the distance between the center of gravity and a point?
