Select a Solid Body by Scripts

zc_steven
zc_steven Member Posts: 7
Name Dropper First Comment
**
edited December 2023 in 3D Design

Hi, I have a SpaceClaim related question and the details are shown below:

There are two solid bodies in the picture attached. Bottom face of the upper solid body and top face of the lower one contact with each other. The name of the upper solid body is specified, so the body can be selected by scripts, such as “BodySelection.CreateByName”. The goal is to select the lower body, whose name is not specified, by scripts. My plan is selecting the lower body by the face which two bodies share. Could I know if it is possible? Please let me know if there are any other methods. Thank you.

Answers

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 355
    25 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited December 2023

    If the two bodies genuinely share the same face, you can use the properties like MyBody.Faces to get the faces of a body and MyFace.Bodies to get the bodies attached to faces. Loop through the faces of the top body and figure out which one has two bodies attached to it. That is the connecting face. Then simply select the body that is not the top and that is the bottom.

    If the two bodies don’t actually share the same face, but have two faces that are identical, you can still loop through all the faces on each body and find the ones that have the same centroid points.

  • zc_steven
    zc_steven Member Posts: 7
    Name Dropper First Comment
    **
    edited December 2023

    Hi Mike,

    Thank you for your explanations and suggestions. Could I know which command can be used to get the centroid points of face and body? I found a syntax called "MeasureHelper.GetCentroid" and looks like it only applies to faces.

    Meanwhile, what if the area of two faces in contact with each other are different? Will there be a similar method to what you introduced in the second paragraph? I wonder if there is a feature like coplanar, with which I can locate the other face.

    @Mike.Thompson said:
    If the two bodies genuinely share the same face, you can use the properties like MyBody.Faces to get the faces of a body and MyFace.Bodies to get the bodies attached to faces. Loop through the faces of the top body and figure out which one has two bodies attached to it. That is the connecting face. Then simply select the body that is not the top and that is the bottom.

    If the two bodies don’t actually share the same face, but have two faces that are identical, you can still loop through all the faces on each body and find the ones that have the same centroid points.

  • Abhijith Rajan
    Abhijith Rajan Member, Employee Posts: 10
    Name Dropper First Anniversary First Answer First Comment
    ✭✭✭

    Hey,

    Try using the Share topology feature to identify the shared faces. Then try getting the bodies from the shared face. An example is shown below

    result = FixImprint.FindAndFix() #Create Imprints
    options=ShareTopologyNamedSelectionOptions()
    options.Tolerance=MM(0.1)
    ShareTopologyNamedSelection.FindAndFix(options) #Create NS of the shared faces
    Connectgroups=Window.ActiveWindow.Groups # gets all groups

    You may loop through the faces in the Connect Group and find the bodies associated with it.

    An example to get the Parent body from the face is
    GetRootPart().Bodies[1].Faces[0].Parent #this would return the Idesignbody associated with the face

  • zc_steven
    zc_steven Member Posts: 7
    Name Dropper First Comment
    **

    @Abhijith Rajan said:
    Hey,

    Try using the Share topology feature to identify the shared faces. Then try getting the bodies from the shared face. An example is shown below

    result = FixImprint.FindAndFix() #Create Imprints
    options=ShareTopologyNamedSelectionOptions()
    options.Tolerance=MM(0.1)
    ShareTopologyNamedSelection.FindAndFix(options) #Create NS of the shared faces
    Connectgroups=Window.ActiveWindow.Groups # gets all groups

    You may loop through the faces in the Connect Group and find the bodies associated with it.

    An example to get the Parent body from the face is
    GetRootPart().Bodies[1].Faces[0].Parent #this would return the Idesignbody associated with the face

    Hi, thank you very much for the suggestions, I will try it in my scripts.