Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey everyone,
I'm trying to figure out how to select vertices through the Maya Python 2.0 API, instead of using the maya.cmds. I'm testing to see how much of a performance boost I can get when using the API.
Example of how I would normally approach selecting vertices in maya.cmds
import maya.cmds as cmds
vertices = [0, 1, 2, 3, 4]
vertex_select_list = []
for vertex in vertices:
vertex_select_list.append("{0}.vtx[{1}]".format('pSphere1', vertex))
cmds.select(vertex_select_list)
Sample of my Python 2.0 API code for trying to select vertices. (This is what I scrounged up from how the internet does it)
import maya.api.OpenMaya as omapi2
vertices = [0, 1, 2, 3, 4]
sel = omapi2.MSelectionList()
sel.add("pSphere1")
dag, mObject = sel.getComponent(0)
mfn_components = omapi2.MFnSingleIndexedComponent(mObject)
mfn_object = mfn_components.create(omapi2.MFn.kMeshVertComponent)
mfn_components.addElements(vertices)
selection_list = omapi2.MSelectionList()
selection_list.add(mfn_object)
omapi2.MGlobal.setActiveSelectionList(selection_list)
The above code does not work as I get the following error...
# Error: RuntimeError: file <maya console> line 12: (kInvalidParameter): Object is incompatible with this method #
My 2 questions...
- In the error above, I get an incompatible error. But I'm not exactly sure what the issue is, as the MSelectionList.add() method requires an MObject. Which I am passing through when I used the MFnSingleIndexedComponent.create() method. Does anyone why I'm getting this error and what it means exactly?
- Is their a better/different way of selecting vertices through the Maya Python 2.0 API? I don't even know if this is the intended way of doing so.
Thanks,
-Eric
Solved! Go to Solution.