Lost Adventurer, Aleks Kirilenko (3D)
LC #42 Pipers Alley

View Full Version : Python list within a list

06-04-2012, 01: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[0] = pPlane1.vtx[4:5] # what i don't want but what I get

# what i do want:
newList = pPlane1.vtx[4], pPlane.vtx[5]

#so then I can do something like

06-04-2012, 04:35 PM
Don't use compact component syntax, e.g.

list = ['pPlane1.vtx[4]', 'pPlane1.vtx[5]']
# 'pPlane1.vtx[4]' #

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[4]', '|pPlane1.vtx[5]']

or if you are using 'filterExpand', use the 'expand' flag.

06-04-2012, 07: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, 08: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[5]', '|pCube1.vtx[6]', '|pCube1.vtx[7]'] #

onlyEdges = cmds.filterExpand(currentSelection, sm=32, ex=1, fp=1)
# Result: ['|pCube1.f[2]', '|pCube1.f[3]', '|pCube1.f[4]'] #

onlyFaces = cmds.filterExpand(currentSelection, sm=34, ex=1, fp=1)
# Result: ['|pCube1.e[2]', '|pCube1.e[3]'] #

CGTalk Moderation
06-04-2012, 08: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.