python - Dividing a list of vertices between left and right sides -


i trying divide spheres selected vertices between left , right (by measuring the vertices x value via pointposition). if have 2 vertices on left , 1 on right selected however, returns have 3 on left, instead of 2 on left , 1 on right.

how should restructure loop correctly creates exclusively left or right list?

import maya.cmds mc  iobj = mc.ls( sl = true, flatten = true ) selsize = len( iobj )  numvert in range ( 0, selsize ):      possel = mc.ls( sl = true, flatten = true )     posselpos = mc.pointposition( possel[ numvert ], world = true )      if posselpos[ 0 ] > 0:          leftverts.append( possel )         leftsidesize = len( leftverts[ 0 ] )         print "lside has " + "%s" % ( leftsidesize )         print leftsidesize                    print leftverts[ 0 ]      elif posselpos[ 0 ] < 0:          rightverts.append( possel )         rightsidesize = len( rightverts[ 0 ] )         print "rside has " + "%s" % ( rightsidesize )                    print rightsidesize         print rightverts[ 0 ] 

if you're getting misleading answer may because you've got verts on 0 coordinate. in test you're going things larger or less zero, nothing sits @ zero.

collecting values pretty simple, can bit more elegantly python list comprehensions

import maya.cmds cmds  # make list of verts, using filterexpand don't  # ranges pcube1.vtx[1:3]  selected = cmds.filterexpand(cmds.ls(sl=true), sm=31)     items_by_position = [ (vtx, cmds.pointposition(vtx)) vtx in selected]  # gives list of [(vertex, position), (vertex, position)] pairs   left = [item item in items_by_position if item[1][0] > 0] right = [item item in items_by_position if item[1][0] < 0] middle = [item item in items_by_position if item[1][0] == 0]  print "left\n", left print "right\n", right print "middle\n", middle 

you might find handy turn left, right , middle lists dictionaries:

selected = cmds.filterexpand(cmds.ls(sl=true), sm=31)        items_by_position = [ (vtx, cmds.pointposition(vtx)) vtx in selected] left = dict([item item in items_by_position if item[1][0] > 0]) right = dict([item item in items_by_position if item[1][0] < 0]) middle = dict([item item in items_by_position if item[1][0] == 0]) 

so grab position of vertex out of list. if flip

(vtx, cmds.pointposition(vtx)) 

into

(cmds.pointposition(vtx), vtx) 

and check item[0] instead of item1, dictionaries keyed position


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -