Skip to content

Instantly share code, notes, and snippets.

@BigRoy
Created June 20, 2022 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BigRoy/0762f283d91c689307f198cb781466c1 to your computer and use it in GitHub Desktop.
Save BigRoy/0762f283d91c689307f198cb781466c1 to your computer and use it in GitHub Desktop.
Maya get faces of mesh per island or poly shell
from maya import cmds
def get_shells(mesh, as_selection_string=True):
"""Return faces per shell of mesh"""
num_shells = cmds.polyEvaluate(mesh, shell=True)
num_faces = cmds.polyEvaluate(mesh, face=True)
unprocessed = set(range(num_faces))
shells = []
while unprocessed:
face_index = next(iter(unprocessed))
shell_faces = cmds.polySelect(mesh, extendToShell=face_index, noSelection=True)
if as_selection_string:
yield ["{}.f[{}]".format(mesh, face_index) for face_index in shell_faces]
else:
yield shell_faces
unprocessed.difference_update(shell_faces)
for node in cmds.ls(sl=1, objectsOnly=True):
for faces in get_shells(node):
print(faces)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment