On Tue, Nov 10, 2015 at 12:21 PM <[email protected]> wrote:

> i have a piece of code that selects a long list of faces on a mesh and
> deletes them
>
> ###########################################
> mesh = ls('handSurface1')[0].getShape()
> faceIndexes = om.MIntArray()
>
> map(faceIndexes.append,
> [55,68,69,70,72,75,76,77,78,79,80,81,82,84,85,86,87,88,89,90,91,92,93,254])
>
> makeMayaComponent()
>
> delete()
> ###########################################
>
> however if there are groups of consecutive faces i need to select how can
> i add these to the list so that i dont have to write each individual face.
> like this:
>
> map(faceIndexes.append, [55,68:70,72,75:82,84:93,254])
>
> #however this is invalid syntax..
>
> thanks,
> Sam
>

Are you trying to populate your MIntArray all in one line? Normally it is
bad practice to use stuff like map, list comprehension, and the like, just
for its side effects. Because basically you are telling python to build a
big list of None values and toss it away, so that you can just get the side
effect of applying the function. So if you are trying to be able to use
that pattern, to achieve it all in one line... you could use range()

map(faceIndexes.append, [55,68,69,70,72] + range(75,93+1) + [254])

​

Or:

import itertools

map(faceIndexes.append, itertools.chain([55,68,69,70,72],
xrange(75,93+1), [254]))

​

Or you could use a loop if you didn't want to generate the garbage None
list:

import itertoolsfor val in itertools.chain([55,68,69,70,72],
xrange(75,93+1), [254]):
    faceIndexes.append(val)

​



> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/ff560c31-f903-42c9-95d8-d05a8d6fffee%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0_ZAapRzKeOEpXXtDnHFi1%2BwSwKyPwwZ%3D%3DASXSAhnBbA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to