Maya Python - How do I query the selection to check if only polyVerts or different?

4.9k views Asked by At

I have a bunch of poly vertex components selected. But sometimes users might select something else along with it (a joint, another mesh, etc.). I'm trying to find a way to test against everything selected to verify it is indeed a vertex. But I can't find anything like this.

Is there a python command to do this directly?

2

There are 2 answers

1
kartikg3 On BEST ANSWER

It may be useful for your use-case to use filterExpand with the selectionMask flag set to 31 to return just polygon vertex components from everything that has been selected.

Following is a simple sample (with some comments): Try it out with different kind of objects and components selected.

import maya.cmds as cmds

# Will return EVERYTHING selected
all_selected = cmds.ls(sl=True)

# Will filter out and return just the verts
# from everything selected
just_the_selected_verts = cmds.filterExpand(sm=31)

Check out filterExpand in the docs here.

0
theodox On

Not exactly. You can find objects which are ready for component selection with cmds.ls(hl=True). You can find selected object which aren't components with cmds.ls(o=True). That means you can isolate only the component selections indirectly like this:

 set (cmds.ls(sl=True, o=False)) - set(cmds.ls(sl=True, o=True))

which makes a set of the whole selection, then one with only the objects, and finally subtracts the second from the first leaving only the component selections (note that will also pass attribute selections if you have those).