How can I can create a named selection of spheres of certain volume?
Erik Kostson
Member, Employee Posts: 200
✭✭✭✭
Say we have a group of spheres and other parts (say enclosure). How can one create a named selection of spheres of certain volume using scripting?
0
Best Answer
-
Probably many ways of doing this, but below is one sample script that does that (modify as needed) - minimum volume and maximum needs to be adjusted to capture the sphere size needed.
mys=[] mye=[] vmin= 4.e-06 # min. volume of spheres in m3 vmax = 4.4e-06 # max. volume of spheres in m3 assembly = GetRootPart() bodies=assembly.Bodies for body in bodies: if body.GetMaster().Shape.IsClosed==True: # check it is a solid body and not surface body s=body.Shape vol=s.Volume if vol >=vmin and vol <=vmax: print('sphere found : ' + str(body.GetName())) mys.append(body) else: mye.append(body) print('sphere not found : ' + str(body.GetName())) primarySelection = Selection.Create(mys) secondarySelection = Selection.Empty() resultmys = NamedSelection.Create(primarySelection, secondarySelection) NamedSelection.Rename("Group1", "Spheres") Selection.Clear() primarySelection = Selection.Create(mye) secondarySelection = Selection.Empty() resultmye = NamedSelection.Create(primarySelection, secondarySelection) NamedSelection.Rename("Group1", "Rest")
One can also look at how many faces the parts have (say a sphere might have only one and that can be then used as a criteria to find all spheres)
0
This discussion has been closed.