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

Member, Moderator, Employee Posts: 108
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

  • Member, Moderator, Employee Posts: 108
    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.

    1. all_parts=DataModel.GetObjectsByType(DataModelObjectCategory.Part)
    2.  
    3. shared_faces_total=0
    4.  
    5. selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
    6. selection.Ids = []
    7.  
    8. for part in all_parts:
    9. body_faces=[]
    10. # Loop over bodies in part
    11. for bo in part.Children:
    12. geo_body=bo.GetGeoBody() # bo is the body in the tree, so getting the actual geometry
    13. body_faces.extend(geo_body.Faces)
    14.  
    15.  
    16. # Now loop over faces to find shared faces
    17. for face in body_faces:
    18. if len(face.Bodies)>1: #we are on a shared face, count it
    19. selection.Ids.Add(face.Id)
    20. shared_faces_total+=1
    21.  
    22. ExtAPI.SelectionManager.NewSelection(selection)
  • Member, Employee Posts: 252
    50 Answers 100 Comments 100 Likes Second Anniversary
    ✭✭✭✭

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

    1. bodies=DataModel.GetObjectsByType(DataModelObjectCategory.Body)
    2. data ={}
    3. for body in bodies:
    4. body_faces=[]
    5. geo_body = body.GetGeoBody()
    6. body_faces.extend(geo_body.Faces)
    7. temp =[]
    8. for face in body_faces:
    9. temp.append(len(face.Bodies))
    10. if max(temp) == 1:
    11. print(geo_body.Name + ' has NO shared faces')

Welcome!

It looks like you're new here. Sign in or register to get started.