Center of Gravity -coordinates of all parts of an assembly

Center of Gravity -coordinates of all parts of an assembly

Toon.Broothaerts
Advocate Advocate
3,804 Views
6 Replies
Message 1 of 7

Center of Gravity -coordinates of all parts of an assembly

Toon.Broothaerts
Advocate
Advocate

Dear all,

 

I'm looking for a way to 'map' the CoG -coordinates of all parts in an existing assembly, and having them in one convenient pane (eg. at "Custom iProperties"). This way, I can use them to automate some extensive calculations.

 

Is there a way (via iLogic?) to reach this situation?

 

Thanks in advance,

Toon Broothaerts


Toon Broothaerts

If my answer solved your question, please mark it as 'solution'. Else, feel free to contact me!
0 Likes
Accepted solutions (2)
3,805 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

Do you want to get each point as a property in custom properties?

Something like this?

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oProps As PropertySet = oAsm.PropertySets.Item("Inventor User Defined Properties")
For Each oOcc As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences.AllLeafOccurrences
	Try
		Dim oDef As PartComponentDefinition = oOcc.Definition
		Dim oCenterOfMass As Point = oDef.MassProperties.CenterOfMass
		'Transform point to the assemblys coordinate system
		oCenterOfMass.TransformBy(oOcc.Transformation)
		Try
			oProps.Item(oOcc.Name).Value = oCenterOfMass.X & ";" & oCenterOfMass.Y & ";" & oCenterOfMass.Z
		Catch
			oProps.Add(oCenterOfMass.X & ";" & oCenterOfMass.Y & ";" & oCenterOfMass.Z, oOcc.Name)
		End Try
		'Dim oWP As WorkPoint = oAsm.ComponentDefinition.WorkPoints.AddFixed(oCenterOfMass) 'Just to see that they are correct
	Catch
	End Try
Next

 

Message 3 of 7

Toon.Broothaerts
Advocate
Advocate

Whoa, thank you Jhoel for the quick response! It's exactly what I need!


Toon Broothaerts

If my answer solved your question, please mark it as 'solution'. Else, feel free to contact me!
Message 4 of 7

Stefan.Rohde
Enthusiast
Enthusiast

Hi Jhoel,

we only need the COG of the assembly, not that of the installed ipt's in the properties.

Did you prepare something?😊
The same would be nice for single IPT's!

 

Best Regards,

 

Stefan

0 Likes
Message 5 of 7

dutt.thakar
Collaborator
Collaborator
Accepted solution

@Stefan.Rohde 

To get the COG of any part or assembly only, you can try the below iLogic code. This will save the COG of current assembly or part in three iProperties.

 

iProperties.Value("Custom","COGX") = iProperties.CenterOfGravity.X
iProperties.Value("Custom","COGY") = iProperties.CenterOfGravity.Y
iProperties.Value("Custom","COGZ") = iProperties.CenterOfGravity.Z

 

Hope this will help.

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
Message 6 of 7

Stefan.Rohde
Enthusiast
Enthusiast
It works.

Thank you very much!
0 Likes
Message 7 of 7

Anonymous
Not applicable

That's great! Thanks Jhoel
Could you give some advice on how to export in excel this results?
The goal is to have en excel file with the global coordinates of CoG of each individual component, along with their Moment of Inertia? I'm working on this script but it exports only the mass properties of the whole assembly.

 

0 Likes