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

Pierre Thieffry
Pierre Thieffry Member, Moderator, Employee Posts: 95
First Anniversary Ansys Employee Solution Developer Community of Practice Member Photogenic
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: 95
    First Anniversary Ansys Employee Solution Developer Community of Practice Member Photogenic

    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)