سؤال

How can I check to the selected items in the variable 'curSel' to test whether they are 'vertices' are not. I'm assuming I would use an if/then statement. So then I can remove any further errors.

I'm guessing I could just test to see if the first item in the list is a vert. If it's a vert then proceed and if not then don't do anything. But how would I write this?

import maya.cmds as cmds

# collect the selected verts
curSel = cmds.ls(sl=1, fl=1)

Working code: Creates locators for each selected vert

import maya.cmds as cmds

selectedVerts = [v for v in cmds.ls(sl=True, fl=True) if '.vtx' in v]

print selectedVerts

for v in selectedVerts:
    pos = cmds.xform( v, query=True, translation=True, worldSpace=True )
    cmds.spaceLocator( p=(pos) )
هل كانت مفيدة؟

المحلول

You can cheat using the filteExpand command instead of ls. FilterExpand without arguments always works on the current selection, and the selectionMask option limits it to a particular component type. So

cmds.filterExpand(sm=31)

will return only the selected vertices and nothing else. If there aren't any verts selected it will return None.

The other way is just to check the selection for the string '.vtx' which is what you'd get from selected verts

selected_verts = [v for v in cmds.ls(sl=True, fl=True) if '.vtx' in v]

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top