How to extract all node ids of a named selection via Mechanical scripting?

Rohith Patchigolla
Rohith Patchigolla Member, Moderator, Employee Posts: 218
100 Comments 25 Answers Second Anniversary 25 Likes
✭✭✭✭

How to extract all node ids of a named selection via scripting, irrespective of whether it has geometric entities (faces for example) or nodes?

Comments

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 218
    100 Comments 25 Answers Second Anniversary 25 Likes
    ✭✭✭✭

    Here is an example code which takes the name of the named selection (please make sure the name is unique and collects all the node ids into a list.

    myNS = ExtAPI.DataModel.GetObjectsByName("test_ns")[0]
    allNodeIds = []
    geomIds = myNS.Location.Ids
    Mesh = ExtAPI.DataModel.MeshDataByName("Global")
    
    if myNS.Location.SelectionType == SelectionTypeEnum.GeometryEntities:
        for geomId in geomIds:
            mR = Mesh.MeshRegionById(geomId)
            nodeIds = mR.NodeIds
            allNodeIds.extend(nodeIds)
    
    else:
        allNodeIds = myNS.Location.Ids
    
    allNodeIds = list(set(allNodeIds))
    print(len(allNodeIds))