Select a Solid Body by Scripts
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
-
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.
0 -
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.
0 -
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 groupsYou 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 face1 -
@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 groupsYou 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 faceHi, thank you very much for the suggestions, I will try it in my scripts.
0