Highlight remote points associated with a selected body.

Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 444
250 Likes Solution Developer Community of Practice Member Ansys Employee First Anniversary
✭✭✭✭

Highlight remote points associated with a selected body.

Comments

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 444
    250 Likes Solution Developer Community of Practice Member Ansys Employee First Anniversary
    ✭✭✭✭

    Assuming you have scoped 1 face in each remote point of your project. The following code will highlight all remote points associated with a selected body. Tested with 2024R1.

    from itertools import chain
    from collections import defaultdict
    
    def flatten_chain(matrix):
        return list(chain(*matrix))
    
    body_id = ExtAPI.SelectionManager.CurrentSelection
    body = ExtAPI.DataModel.GeoData.GeoEntityById(body_id.Ids[0])
    
    face_ids = [face.Id for face in body.Faces]
    rps = ExtAPI.DataModel.Project.Model.RemotePoints.Children
    
    rps_dict = defaultdict(list)
    for rp in rps:
        rps_dict[str(list(rp.Location.Ids))].append(rp)
    
    filtered_rps_temp = []
    for face_id in face_ids:
        filtered_rps_temp.append(rps_dict[str([face_id])])
    
    filtered_rps = flatten_chain(filter(None, filtered_rps_temp))
    
    ExtAPI.DataModel.Tree.Activate(filtered_rps)
    ExtAPI.SelectionManager.ClearSelection()