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

Options
Pierre Thieffry
Pierre Thieffry Member, Moderator, Employee Posts: 101
First Anniversary Ansys Employee Solution Developer Community of Practice Member Photogenic

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: 101
    First Anniversary Ansys Employee Solution Developer Community of Practice Member Photogenic
    Options

    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)))