Center of gravity of a solid body

Center of gravity of a solid body

vpeuvion
Advocate Advocate
795 Views
2 Replies
Message 1 of 3

Center of gravity of a solid body

vpeuvion
Advocate
Advocate

Hello everybody.
I try to access the values of the coordinates of the center of gravity of a solid body from ilogic without success. Does anyone have a lead?

Thank you.

Vincent.

2021-12-13_15-13-07.jpg

 

0 Likes
Accepted solutions (1)
796 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @vpeuvion.  I worked on something like this before.  Check out this link to another related post helps you out.

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/create-a-point-for-center-of-gravity-as... 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

vpeuvion
Advocate
Advocate

Hi WCrihfield .  

Thank you for your reply.
That answers my question. Attached is the code derived from yours that I used to do my testing if that might help anyone in the future. The values correspond to those in the solid properties window.

Vincent.

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("This rule only works for Part Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oWP As WorkPoint

Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oBodies As SurfaceBodies = oPDef.SurfaceBodies
Dim oBody As SurfaceBody
Dim oCorner As Point, oD1, oD2, oD3 As Vector
Dim oC1, oC3, oCP As Point
Dim oL1 As LineSegment
Dim oHalfVector As Vector

oBody = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter," Select Body")
oBody.OrientedMinimumRangeBox.GetOrientedBoxData(oCorner, oD1, oD2, oD3)
oC1 = oCorner.Copy
oC1.TranslateBy(oD1)
oC3 = oCorner.Copy
oC3.TranslateBy(oD3)
oL1 = oTG.CreateLineSegment(oC1, oC3)
oCP = oL1.MidPoint.Copy
oHalfVector = oD2.Copy
oHalfVector.ScaleBy(.5)
oCP.TranslateBy(oHalfVector)
MessageBox.Show("X : " & Round(oCP.X*10,3) & " Y : " & Round(oCP.Y*10,3) & " Z : " & Round(oCP.Z*10,3))