Skip to content

Instantly share code, notes, and snippets.

@justinfx
Created September 17, 2012 17:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinfx/3738519 to your computer and use it in GitHub Desktop.
Save justinfx/3738519 to your computer and use it in GitHub Desktop.
function for returning the selectable shells of a poly
def getShellFaces(poly, asString=False):
shells = set()
faces = set()
total = cmds.polyEvaluate(poly, s=True)
for f in xrange(cmds.polyEvaluate(poly, f=True)):
if len(shells) >= total:
break
if f in faces:
continue
shell = cmds.polySelect(poly, extendToShell=f)
faces.update(shell)
if asString:
val = "%s.f[%d:%d]" % (poly, min(shell), max(shell))
else:
val = min(shell)
shells.add(val)
return list(shells)
poly = 'polySurface1'
# get the first face of each shell to be selected
# later with polySelect
faceIds = getShellFaces(poly)
for f in shells:
cmds.polySelect(poly, extendToShell=f)
# get the string name of the entire shell in the
# form of polySurface1.f[x:y] to be used with select
shells = getShellFaces(poly, True)
for f in shells:
cmds.select(f)
@sickiziu
Copy link

hello!
what if faces are not numbered in ascending order? what if faces 0, 3, 5, and 7 compose into shell?

@thirstydevil
Copy link

Just what I needed. Thanks Justin.
@sickiziu, as each face is extended to a group and then added to a set, this should work for all scenarios.

@Aekschen
Copy link

Thanks! should be like this I assume.

faceIds = getShellFaces(poly)
for f in faceIds:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment