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.
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)
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.
I was looking at the tutorial on calculating CoG on parts and at the end it says: Sign-up for my free email newsletter to download the complete code that drills down through every parts and product node in the tree and displays the results.
I already get your newsletter. Ho do I get this code?
Hi Kris. TraverseProduct is simply a recursive function to scroll down the spec tree. Here is it:
Sub TraverseProduct(oInProduct As Product)
Dim oInstances As Products
Set oInstances = oInProduct.Products
‘—–No instances found then this is CATPart
If oInstances.Count = 0 Then
Msgbox “This is a CATPart with part number ” & oInProduct.PartNumber
Exit Sub
End If
‘—–Found an instance therefore it is a CATProduct
Msgbox “This is a CATProduct with part number ” & oInProduct.ReferenceProduct.PartNumber
Dim k As Integer
For k = 1 To oInstances.Count
Dim oInst As Product
Set oInst = oInstances.Item(k)
‘apply design mode
oInstances.Item(k).ApplyWorkMode DESIGN_MODE
Call TraverseProduct(oInst)
Next
End Sub
When I run Catia command start from VBA to measure inertia with a selection in place it opens measure 3d inertia. I require 2d inertia as I am selecting surface. Kindly suggest method to get 2d inertia properties of a selected surface.
After I initially left a comment I seem to have clicked the -Notify me when new comments are added- checkbox
and now each time a comment is added I receive 4 emails
with the exact same comment. There has to be a way you are able to remove me from
that service? Thanks!
ho w do i get the units of the measuremnet value like cog or inertia matrix in vb.net
I was very happy to discover this site. I want
to to thank you for your time for this particularly wonderful read!!
I definitely really liked every part of it and I have
you book marked to look at new stuff on your blog.
Hello Emmett,
First of all thank you!
I have learned CATIA macros from your tutorials and books only.
I have created a number of Catia macros independently.
But I need your help for one macro I am developing at present. The purpose of this macro is to measure mass of each CATpart present in CATProduct.
This article helped me to write correct code to get the mass using .GetTechnologicalObject(“Inertia”).mass
But this is measuring mass of hidden elements/bodies also.
I want to measure mass of only shown elements.
Can you please help?
can we measure COGPostion of hole