This article will show you how to find the center of gravity position of parts and products using a CATIA macro. Engineers often times need to know the center of gravity of each component in a model. Calculating all these by hand could take a long time and is prone to mistakes, thus we will automate the process. We will use the inertia object to compute parts and product’s mass and position of the center of gravity.

The first assumption is that the active document is a CATProduct and the next is that material properties have been applied to all parts. The code will loop through every node in the product tree and identify if it is a part or a product before computing the center of gravity.catia center of gravity inertia

The method GetTechnologicalObject("Inertia") is used on the product allowing you to retrieve this object. GetCOGPosition method is then used on the oInertia object to read the corresponding inertia data. GetCOGPosition retrieves the x,y,z coordinate position of the center of gravity:

  • oCoordinates(0) is the X coordinate
  • oCoordinates(1) is the Y coordinate
  • oCoordinates(2) is the Z coordinate

So to retrieve the position of the center of gravity of oInertia:

Dim oCoordinates(2)

Dim oInertia As AnyObject

Set oInertia = product1.GetTechnologicalObject(“Inertia”)

oInertia.GetCOGPosition oCoordinates

 

The results are displayed in a Msgbox like so:

MsgBox product1.Name & “, Center of gravity : X = ” & CStr(oCoordinates(0)) & “, Y = ” + CStr(oCoordinates(1)) & “, Z = ” + CStr(oCoordinates(2)

catia part center of gravitycatia product center of gravity

The display units are:

  • Kilogram (Kg) for Mass
  • Square meter (M^2) for Wet Area
  • Cubic meter (M^3) for Volume
  • Meter (M) for Position
  • Square Kilogram meter ((KgM)^2) for Inertia Matrix and Principal Moments
  • Kilogram per cubic meter (Kg/M^3) for Density

Sign-up for my free email  course to download the complete code that drills down through every parts and product node in the tree and displays the results. The next step you can do for good practice is to export the results into an Excel spreadsheet, a process explained in VB Scripting for CATIA V5.