How can I count and select shared faces in multibody parts with shared topology?

Pierre Thieffry
Pierre Thieffry Member, Moderator, Employee Posts: 107
25 Answers Second Anniversary 10 Comments 25 Likes
✭✭✭✭
edited October 2023 in Structures

I have a model with shared topology. I want to identify which faces are shared between bodies, get a count of them and select them.

Answers

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

    Here's one way to do it. Shared faces will have two bodies associated to them. The following script looks at all parts. For each parts, bodies are investigated and faces collected. Then we scan the faces to find which ones have two (or more) bodies associated to them.

    Note that the count of faces includes duplicate faces.

    all_parts=DataModel.GetObjectsByType(DataModelObjectCategory.Part)
    
    shared_faces_total=0
    
    selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
    selection.Ids = []
    
    for part in all_parts:            
        body_faces=[]               
        # Loop over bodies in part
        for bo in part.Children:            
            geo_body=bo.GetGeoBody() # bo is the body in the tree, so getting the actual geometry            
            body_faces.extend(geo_body.Faces)
    
    
        # Now loop over faces to find shared faces      
        for face in body_faces:
            if len(face.Bodies)>1: #we are on a shared face, count it
                selection.Ids.Add(face.Id)
                shared_faces_total+=1
    
    ExtAPI.SelectionManager.NewSelection(selection)
    
  • M
    M Member, Employee Posts: 244
    50 Answers 100 Comments 100 Likes Second Anniversary
    ✭✭✭✭

    Shorter, for a query about how to find bodies that do not have shared topology.

    bodies=DataModel.GetObjectsByType(DataModelObjectCategory.Body)
    data ={}
    for body in bodies:
        body_faces=[]  
        geo_body = body.GetGeoBody()
        body_faces.extend(geo_body.Faces)
        temp =[]
        for face in body_faces:
            temp.append(len(face.Bodies))
        if max(temp) == 1:
            print(geo_body.Name + ' has NO shared faces')