Create a Point at the Centre of Gravity with iLogic

I was looking through some of my old iLogic code recently, and I ran across a utility that I wrote, which places a work point at the centre of gravity (COG), of an assembly model. I believe that the code was broadly based on an API sample for creating a work point based on 3 coordinates.

The code is pretty simple, it updates the physical properties (iProperties), then creates a work point called “COG” at the at the centre of gravity. If a work point called “COG” already exists, it deletes it and creates a new one, at the updated centre of gravity.

In the animation below, you can see the COG being created and then updated when an additional part is added to the assembly.

Click me for high res version

Here’s the iLogic code:

'This iLogic code by @ClintBrown3D, originally posted at

'Check if this is an assembly
UnofficialInventor = ThisApplication.ActiveDocument
If UnofficialInventor.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("This rule can only be run in an Assembly File >>>> Now Exiting Rule...", "Unofficial Inventor")
End If

'Delete "COG" if it exists
Dim oDoc As AssemblyDocument = ThisApplication.ActiveEditDocument
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

'Update Physical Properties
Call ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
'Create the workpoint
Dim oSP As WorkPoint = oDef.WorkPoints.Item("COG")
End Try

pt = iProperties.CenterOfGravity
oXX = pt.X
oYY = pt.Y
oZZ = pt.Z

iProperties.Value("Custom", "X")= oXX
iProperties.Value("Custom", "Y")= oYY
iProperties.Value("Custom", "Z")= oZZ

oDoc = ThisDoc.Document
Dim oCompDef As AssemblyComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

oWorkPoint1 = oCompDef.WorkPoints.AddFixed(oTG.CreatePoint((oXX / 10), (oYY / 10), (oZZ / 10)))
oWorkPoint1.Name = "COG"
oWorkPoint1.Grounded = True

Comments are closed.

Create a website or blog at

Up ↑

%d bloggers like this: