How can we iterate over all named sel. in Spaceclaim trying to get the centroid of a Solid body

Options
Erik Kostson
Erik Kostson Member, Employee Posts: 124
First Answer Name Dropper First Anniversary Ansys Employee
edited May 2 in 3D Design

Say we have many named selections (NS) /groups in Spaceclaim, consisting of Solid 3D bodies. How can we automatically get the centroid of all these bodies belonging to the different NS/groups?

Best Answer

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 124
    First Answer Name Dropper First Anniversary Ansys Employee
    Answer ✓
    Options

    Below is a code that does that (loops and gets the centroind / cen ):

    groups = GetActiveWindow().ActiveWindow.Groups
    for ns in groups:
        nm=ns.GetName()
        print(nm)
        me=ns.Members
        for mem in me:
            if isinstance(mem, DesignBody): # only DesignBodies
                mp=mem.MassProperties.RawSubject
                cen=mp.Center # get centroid
                print(cen[1]) # print y coordinate
    
This discussion has been closed.