Dear CATIA users,
I think this is an easy one, but I've been struggling with this for a very long time now. I have a product consisting of a (1) subproduct and a (2) 3dpart. I want to get mass and inertia of (1) and (2), separately, using GetInertiaElement(). I'm able to get the mass of the whole Product and the 3dpart, but not for the subproduct... This is what I have:
' 1- Gets the current Editor
Dim myEditor As Editor
Set myEditor = CATIA.ActiveEditor
' 2- Gets the Context from the Editor
Dim MyContext As PLMAppContext
Set MyContext = myEditor.GetService("PLMProductContext")
Dim myRootOccurrence As VPMRootOccurrence
Set myRootOccurrence = MyContext.RootOccurrence
Dim myMCXParent As VPMReference
Set myMCXParent = myRootOccurrence.ReferenceRootOccurrenceOf
'3- Retrieving the PLMProductContext object as a service associated to the editor
Dim oPLMProductContext As PLMProductContext
Set oPLMProductContext = myEditor.GetService("PLMProductContext")
'4- Retrieves the list of instances within the input reference
Dim TheInstances As VPMInstances
Set TheInstances = myMCXParent.Instances
Dim oVPMInst As VPMInstance
Set oVPMInst = TheInstances.Item(1) ' Index=1 is the subassembly index #
'Getting the dynamical properties of each part (Mass, Inertia tensor, center of gravity)
Set theInertiaService = CATIA.ActiveEditor.GetService("InertiaService")
Dim theInertiaElement As Inertia
Dim theInertiaElement2 As Object
Set theInertiaElement = theInertiaService.GetInertiaElement(oVPMInst)
Set theInertiaElement2 = theInertiaElement
Dim theMass As Double
Dim theMoments(2)
Dim theMatrix(8)
theInertiaElement2.GetInertiaMatrix theMatrix ' Here is the problematic line
theInertiaElement2.GetPrincipalMoments theMoments
theMass = theInertiaElement2.GetMass
Running this will result in the error "The method GetInertiaMatrix failed". Does anyone know how I can fix this and get the mass / moments of the subassembly?
I think this is an easy one, but I've been struggling with this for a very long time now. I have a product consisting of a (1) subproduct and a (2) 3dpart. I want to get mass and inertia of (1) and (2), separately, using GetInertiaElement(). I'm able to get the mass of the whole Product and the 3dpart, but not for the subproduct... This is what I have:
' 1- Gets the current Editor
Dim myEditor As Editor
Set myEditor = CATIA.ActiveEditor
' 2- Gets the Context from the Editor
Dim MyContext As PLMAppContext
Set MyContext = myEditor.GetService("PLMProductContext")
Dim myRootOccurrence As VPMRootOccurrence
Set myRootOccurrence = MyContext.RootOccurrence
Dim myMCXParent As VPMReference
Set myMCXParent = myRootOccurrence.ReferenceRootOccurrenceOf
'3- Retrieving the PLMProductContext object as a service associated to the editor
Dim oPLMProductContext As PLMProductContext
Set oPLMProductContext = myEditor.GetService("PLMProductContext")
'4- Retrieves the list of instances within the input reference
Dim TheInstances As VPMInstances
Set TheInstances = myMCXParent.Instances
Dim oVPMInst As VPMInstance
Set oVPMInst = TheInstances.Item(1) ' Index=1 is the subassembly index #
'Getting the dynamical properties of each part (Mass, Inertia tensor, center of gravity)
Set theInertiaService = CATIA.ActiveEditor.GetService("InertiaService")
Dim theInertiaElement As Inertia
Dim theInertiaElement2 As Object
Set theInertiaElement = theInertiaService.GetInertiaElement(oVPMInst)
Set theInertiaElement2 = theInertiaElement
Dim theMass As Double
Dim theMoments(2)
Dim theMatrix(8)
theInertiaElement2.GetInertiaMatrix theMatrix ' Here is the problematic line
theInertiaElement2.GetPrincipalMoments theMoments
theMass = theInertiaElement2.GetMass
Running this will result in the error "The method GetInertiaMatrix failed". Does anyone know how I can fix this and get the mass / moments of the subassembly?