maya Finding scene objects Working with component selections


When working with components, such as vertices or uv points, Maya defaults to returning a colon-separated range rather than individual items:

 print'pCube1.vtx[*]')  # get all the vertices in the cube
 # [u'pCube1.vtx[0:7]']

You can use ls with the flatten option to force Maya to expand the range notation into individual component entries:

expanded ='pCube1.vtx[*]', flatten=True)
print expanded
# [u'pCube1.vtx[0]', u'pCube1.vtx[1]', u'pCube1.vtx[2]', u'pCube1.vtx[3]', u'pCube1.vtx[4]', u'pCube1.vtx[5]', u'pCube1.vtx[6]', u'pCube1.vtx[7]']

This form is usually better when looping, since you don't have write any code to turn a string like pCube1.vtx[0:7] into multiple individual entries.

You can also get the same result using the filterExpand command.