View Full Version : Python list within a list
06-04-2012, 02:58 PM
I am pretty new to python and I am still trying to get hold of the basics. I have a list which contains mutilple vertices. How can i select one of them?
list = [u'pPlane1.vtx[4:5]']
list = pPlane1.vtx[4:5] # what i don't want but what I get
# what i do want:
newList = pPlane1.vtx, pPlane.vtx
#so then I can do something like
06-04-2012, 05:35 PM
Don't use compact component syntax, e.g.
list = ['pPlane1.vtx', 'pPlane1.vtx']
# 'pPlane1.vtx' #
The problem is that 'pPlane1.vtx[4:5]' is just a single string, not a list of components, thus it becomes the first entry into the list.
When using the 'ls' command with components, always use the 'flatten' (and 'long') flags.
cmds.ls(sl=True, fl=True, l=True)
# ['|pPlane1.vtx', '|pPlane1.vtx']
or if you are using 'filterExpand', use the 'expand' flag.
06-04-2012, 08:32 PM
exactly what I was looking for! Thank you!
I have been unsuccessful at using the filterExpand command. Instead I created a for loop with something like , which works well. Is there a way with filterExpand to execute the same function?
newList = 
for i in List:
tmp = cmds.ls(i+'.cv ', fl=1)
06-04-2012, 09:29 PM
you'll need to reference the docs on filterExpand, each component type has a special integer associated with it.
cmds.select(['|pCube1.vtx[5:7]', '|pCube1.f[2:4]', '|pCube1.e[2:3]'], replace=True)
currentSelection = cmds.ls(sl=True)
onlyVerts = cmds.filterExpand(currentSelection, selectionMask=31, expand=True, fullPath=True)
# Result: ['|pCube1.vtx', '|pCube1.vtx', '|pCube1.vtx'] #
onlyEdges = cmds.filterExpand(currentSelection, sm=32, ex=1, fp=1)
# Result: ['|pCube1.f', '|pCube1.f', '|pCube1.f'] #
onlyFaces = cmds.filterExpand(currentSelection, sm=34, ex=1, fp=1)
# Result: ['|pCube1.e', '|pCube1.e'] #
06-04-2012, 09:29 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2014, Jelsoft Enterprises Ltd.