×
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

How to get mass of subassembly with VBA

How to get mass of subassembly with VBA

How to get mass of subassembly with VBA

(OP)
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?

RE: How to get mass of subassembly with VBA

Search for "Computing a Mass and a Center of Gravity's Position" in the V5Automation.chm. It may help you.

RE: How to get mass of subassembly with VBA

(OP)
Thanks lardmand363 for your reply:)

Actually, the code above belongs to CATIA V6, so documentation in V5Automation.chm (CATIA V5 API) might not have helped.

In fact, I solved this problem earlier this week.

To compute a Product mass you have to go at higher level in the product model. You can achieve this by modifying the code I've already posted with this version:





Sub ExtractKinematicsMain2()


' 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


'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(myRootOccurrence.Occurrences.Item(2))
Set theInertiaElement2 = theInertiaElement
Dim theMass As Double
Dim theMoments(2)
Dim theMatrix(8)
theInertiaElement2.GetInertiaMatrix theMatrix
theInertiaElement2.GetPrincipalMoments theMoments
theMass = theInertiaElement2.GetMass
MsgBox "The Mass: " & theMass

End Sub




Thanks for your reply,

Regards,

Jean-Philippe

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