How can I can create a named selection of spheres of certain volume?

Member, Moderator, Employee Posts: 311
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭
edited June 2024 in 3D Design

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?

Best Answer

  • Member, Moderator, Employee Posts: 311
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited June 2024 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.

    1. mys=[]
    2. mye=[]
    3. vmin= 4.e-06 # min. volume of spheres in m3
    4. vmax = 4.4e-06 # max. volume of spheres in m3
    5. assembly = GetRootPart()
    6. bodies=assembly.Bodies
    7.  
    8. for body in bodies:
    9. if body.GetMaster().Shape.IsClosed==True: # check it is a solid body and not surface body
    10. s=body.Shape
    11. vol=s.Volume
    12. if vol >=vmin and vol <=vmax:
    13. print('sphere found : ' + str(body.GetName()))
    14. mys.append(body)
    15. else:
    16. mye.append(body)
    17. print('sphere not found : ' + str(body.GetName()))
    18.  
    19.  
    20.  
    21.  
    22. primarySelection = Selection.Create(mys)
    23. secondarySelection = Selection.Empty()
    24. resultmys = NamedSelection.Create(primarySelection, secondarySelection)
    25. NamedSelection.Rename("Group1", "Spheres")
    26. Selection.Clear()
    27. primarySelection = Selection.Create(mye)
    28. secondarySelection = Selection.Empty()
    29. resultmye = NamedSelection.Create(primarySelection, secondarySelection)
    30. 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)

This discussion has been closed.