How do I select bodies by centroid in DesignModeler scripting?

Landon Mitchell Kanner
Landon Mitchell Kanner Member, Employee Posts: 177
First Answer First Comment 5 Likes First Anniversary

I want to select bodies by centroid via scripting in DesignModeler

Tagged:

Answers

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 177
    First Answer First Comment 5 Likes First Anniversary
    edited December 2023
    centroid = [0.25, 1.5, 4.5]
    tolerance = 0.001
    bodies_to_select = []
    for body in ExtAPI.DataModel.GeoData.Bodies:
        if abs(body.Centroid[0] - centroid[0]) < tolerance:
            if abs(body.Centroid[1] - centroid[1]) < tolerance:
                if abs(body.Centroid[2] - centroid[2]) < tolerance:
                    bodies_to_select.append(body)
    
    ExtAPI.SelectionManager.ClearSelection()
    ExtAPI.SelectionManager.AddSelection(bodies_to_select)