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

amusthaf
Member Posts: 12
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.
0
Best 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:
1