Centre of Gravity - Mechanical Script

Erik Kostson
Member, Moderator, Employee Posts: 311
✭✭✭✭
How can I get the centre of gravity of an assembly of parts using scripting inside mechanical?
0
Comments
-
We can take this very nice script here (https://discuss.ansys.com/discussion/423/extract-mass-per-body-through-scripting), and add the following to calculate the Centre of Gravity in x (cogx), y (cogy) and z (cogz):
- #add at the top and before main loop (constant declaration)
- sumt=0
- summx=0
- cogx=0
- summy=0
- cogy=0
- summz=0
- cogz=0
- ##add inisde main loop
- sumt=sumt+bodyMassValue
- summx=summx+bodyCentroidXValue*bodyMassValue
- summy=summy+bodyCentroidYValue*bodyMassValue
- summz=summz+bodyCentroidZValue*bodyMassValue
- #add outside loop and at the end
- cogx=summx/sumt
- cogy=summy/sumt
- cogz=summz/sumt
1
This discussion has been closed.