Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

VBA macro to determine Mass and Center Of Gravity of a product

Status
Not open for further replies.

FabienF

New member
Jul 5, 2017
19
0
0
FR
Hello,
I am trying to create a VBA macro that gets the mass and center of gravity of an assembly depending on the nodes (sub products or sub sub products) I select in the general assembly.
Lets say that my general assembly comprises of several nodes (sub products A,B , C ,D....) and in some of these nodes there are other sub products ( lets say A_1, A_2....)
The aim, if I would do it manually, is to select certain nodes (whether it be at level A or at level A_1) and get the mass and the COG of that configuration (selected nodes)with the measure inertia tool.
So far, with this code I have succeeded in finding the mass and COG of only ONE node:
Sub CATMain()
--------------------------------------------
Dim CATIA As Object
Set CATIA = GetObject(, "CATIA.Application")
Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
Set selection1 = productDocument1.Selection
Set product1 = productDocument1.Product
Set products1 = product1.Products
Set product2 = products1.Item("A")
Set products1 = product2.Parent

Dim oInertia As AnyObject
Set oInertia = product2.GetTechnologicalObject("Inertia")

Dim dMass As Double
dMass = oInertia.Mass

Dim dCoordinates(2)
oInertia.GetCOGPosition dCoordinates


MsgBox product2.Name & ": Mass = " & CStr(dMass) & ", Center of gravity : X = " & CStr(dCoordinates(0)) & ", Y = " + CStr(dCoordinates(1)) & ", Z = " + CStr(dCoordinates(2))

End Sub
------------------------------------------------------------------
Could someone help me with how to get the inertia properties of a multiple selection (i.e several nodes selected: A_1+A_2+D)? How do I add several nodes(sub products) to a selection and access the inertia properties of that selection (containing several nodes) ?

Thanking you in advance.
 
Status
Not open for further replies.
Back
Top