Centre of Gravity - Mechanical Script

Erik Kostson
Erik Kostson Member, Employee Posts: 87
First Answer Name Dropper First Anniversary Ansys Employee
edited November 2023 in Structures

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

Comments

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 87
    First Answer Name Dropper First Anniversary Ansys Employee
    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):

    #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
    
This discussion has been closed.