That's perfect, thanks for all the help. It was the cmds.polySelect(extendToShell=True) that was key to fixing the problem. I didn't know it existed!
Cheers Echo7 On Monday, September 17, 2012 6:10:08 PM UTC+1, Justin Israel wrote: > > Small correction made to the 4th line: > total = cmds.polyEvaluate(poly, s=True) > > https://gist.github.com/3738519 > > > On Mon, Sep 17, 2012 at 10:07 AM, Justin Israel > <justin...@gmail.com<javascript:>> > wrote: > > I don't seem to see a direct method for listing shells, other than the > > count. But here is a possible approach. You can loop over the faces, > > and determine that actual shells using polySelect extendToShell. > > > > Here is a function that can take a poly name and return either the > > first face id of each shell, or the string name for the entire shell. > > Depends on how you want to use it. I tried to make it a bit more > > efficient by breaking early once we have the number of shells we > > expected, and to also skip over faces that were part of the previously > > collected shell. Reduces the number of polySelect calls to just the > > first face of each one. > > > > https://gist.github.com/3738519 > > > > def getShellFaces(poly, asString=False): > > shells = set() > > faces = set() > > total = cmds.polyEvaluate(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) > > > > > > > > On Mon, Sep 17, 2012 at 3:45 AM, Sumant Shenoy > > <shenro...@gmail.com<javascript:>> > wrote: > >> hey Echo7 > >> just find the number of shells and write a loop for selecting using > range > >> > >> -- > >> view archives: http://groups.google.com/group/python_inside_maya > >> change your subscription settings: > >> http://groups.google.com/group/python_inside_maya/subscribe > -- view archives: http://groups.google.com/group/python_inside_maya change your subscription settings: http://groups.google.com/group/python_inside_maya/subscribe