Centre of Gravity - Mechanical Script

Member, Moderator, Employee Posts: 311
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭
edited November 2023 in Structures

How can I get the centre of gravity of an assembly of parts using scripting inside mechanical?

Comments

  • Member, Moderator, Employee Posts: 311
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited November 2023

    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):

    1. #add at the top and before main loop (constant declaration)
    2. sumt=0
    3. summx=0
    4. cogx=0
    5. summy=0
    6. cogy=0
    7. summz=0
    8. cogz=0
    9. ##add inisde main loop
    10. sumt=sumt+bodyMassValue
    11. summx=summx+bodyCentroidXValue*bodyMassValue
    12. summy=summy+bodyCentroidYValue*bodyMassValue
    13. summz=summz+bodyCentroidZValue*bodyMassValue
    14. #add outside loop and at the end
    15. cogx=summx/sumt
    16. cogy=summy/sumt
    17. cogz=summz/sumt
This discussion has been closed.