Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get vertex as single array

Tags:

python

api

maya

I need to get all the selected vertices and store them in an array so I can loop through and find out information about each vert.

Although I cannot figure this out.

sel = cmds.ls(sl=1)
print sel

Returns:

//[u'pCube1.vtx[50:53]', u'pCube1.vtx[74:77]']

More or less I need my 'sel' variable to print out this:

pCube1.vtx[50]
pCube1.vtx[51]
pCube1.vtx[52]
pCube1.vtx[53]
pCube1.vtx[74]
pCube1.vtx[75]
pCube1.vtx[76]
pCube1.vtx[77]

Does anyone know how to do this without literally stripping the string apart? I think that's a very messy way around it and would like to know if there's another possibility! Maybe with the Maya API using OpenMaya?

like image 926
Shannon Hochkins Avatar asked Jan 14 '23 01:01

Shannon Hochkins


1 Answers

Well, it seems research has paid off!

cmds.ls(sl=1, fl=1)

the 'fl' flag stands for "Flatten", Flatten returns a list of objects so that each component is identified individually.

like image 180
Shannon Hochkins Avatar answered Jan 19 '23 11:01

Shannon Hochkins