View -> Center of Gravity to get the coordinate of COG and then assign a work point using the values of this coordinate. But the work point can't be associated with the changes of COG. Please see the attached image.
When you use the VBA code for assigning work point in COG below, it will be associative with the COG changed.
Thanks,
River
Public Sub WorkPointAtMassCenter()
' Check to make sure a part document is active.
If ThisApplication.ActiveDocumentType kPartDocumentObject Then
MsgBox "A part document must be active."
Exit Sub
End If
' Set a reference to the active document.
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
' Get the Center of Mass.
Dim oCenterOfMass As Point
Set oCenterOfMass = oDoc.ComponentDefinition.MassProperties.CenterOfMass
' Check to see if a work point for center of mass already exists.
' This uses the name of the work feature to identify it.
On Error Resume Next
Dim oWorkPoint As WorkPoint
Set oWorkPoint = oDoc.ComponentDefinition.WorkPoints.Item("Center Of Mass")
If Err.Number = 0 Then
Dim oFixedDef As FixedWorkPointDef
Set oFixedDef = oWorkPoint.Definition
oFixedDef.Point = oCenterOfMass
oDoc.Update
Else
' Create a new workpoint at the location of the center of mass.
Set oWorkPoint = oDoc.ComponentDefinition.WorkPoints.AddFixed(oCenterOfMass)
' Rename the work point.
oWorkPoint.Name = "Center Of Mass"
End If
End Sub
Thanks,
River Cai
Inventor Quality Assurance Team
Autodesk, Inc.
Email: River-Yijiang.Cai@autodesk.com