How can I get the node and element range for bodies in Mechanical Scripting?

Pierre Thieffry
Pierre Thieffry Member, Moderator, Employee Posts: 107
25 Answers Second Anniversary 10 Comments 25 Likes
✭✭✭✭

I'd like to know min and max node numbers or element numbers for specific bodies in Mechanical. I could obviously select bodies, convert to node and elements and find some related information. Yet scripting would likely be more efficient.

Answers

  • Pierre Thieffry
    Pierre Thieffry Member, Moderator, Employee Posts: 107
    25 Answers Second Anniversary 10 Comments 25 Likes
    ✭✭✭✭

    Here's a sample script - just change the filter name to fit your model:

    bodies=DataModel.GetObjectsByType(DataModelObjectCategory.Body)
    mesh=DataModel.MeshDataByName(DataModel.MeshDataNames[0])
    filter_name='my_body_name'
    
    for bo in bodies:
    if filter_name in bo.Name:
    bg=bo.GetGeoBody()
    bo_mesh=mesh.MeshRegionById(bg.Id)
    el_ids=bo_mesh.ElementIds
    node_ids=bo_mesh.NodeIds
    print('{0} : Element range [{1},{2}]\n\tNode range [{3},{4}]\n'.format(bo.Name,min(el_ids),max(el_ids),min(node_ids),max(node_ids)))