Selecting an element/node by its Id, how to find which body the element/node corresponds to?

amusthaf Member Posts: 12
Name Dropper First Comment
edited June 21 in Structures

I have an element id, but I need the body to which the element corresponds to.

In general, I have a named selection with all the elements of a body. I need to find out to which body the elements correspond to in the assembly.

Best Answer

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 596
    100 Answers 250 Likes 100 Comments First Anniversary
    Answer ✓

    Hi @amusthaf ,

    The below script should help:

    element_ns = ExtAPI.DataModel.GetObjectsByName('NS_Elements')[0] 
    first_element_id = element_ns.Location.Ids[0]
    mesh_data = ExtAPI.DataModel.Project.Model.Analyses[0].MeshData
    bodies = ExtAPI.DataModel.Project.Model.Geometry.GetChildren(DataModelObjectCategory.Body, True)
    for body in bodies:
        geobody = body.GetGeoBody()
        mesh_for_body = mesh_data.MeshRegionById(geobody.Id)
        if first_element_id in mesh_for_body.ElementIds:
            print('Element ' + str(first_element_id) + ' is in body named: ' + str(body.Name))

    This is NS_Elements:

    This is the geometry structure:

    And the script returns:

    Which we can verify as follows: