import maya.api.OpenMaya as om
# meshFn is a MFnMesh attached to an object in the scene
# faceIds is a MIntArray
compFn = om.MFnSingleIndexedComponent()
compObj = compFn.create(om.MFn.kMeshPolygonComponent)
compFn.addElements(faceIds)
sList = om.MSelectionList()
sList.add((meshFn.getPath(), compObj))
om.MGlobal.setActiveSelectionList(sList)
import pymel.core as pm
pmMesh = pm.PyNode(meshFn.fullPathName())
pmFaces = pm.MeshFace(pmMesh, faceIds)
pm.select(pmFaces)
import maya.api.OpenMaya as om
''' following the declaration of a class for a command '''
def doIt(self):
compFn = om.MFnSingleIndexedComponent()
compObj = compFn.create(om.MFn.kMeshPolygonComponent)
compFn.addElements(faceIds)
sList = om.MSelectionList()
sList.add((meshFn.getPath(), compObj))
om.MGlobal.setActiveSelectionList(sList)
def undoIt(self):
#add cached previous selection
if not len(previous_cached):
#
sList = om.MSelectionList()
om.MGlobal.setActiveSelectionList(sList)
else:
#
compFn = om.MFnSingleIndexedComponent()
compObj = compFn.create(om.MFn.kMeshPolygonComponent)
compFn.addElements(previous_cached)
Hey Michael,
There was a thread recently about the API and undo.
My takeaway is that you’re exactly right; there is few (if any) ways of integrating with Maya’s undo other than implementing a command plug-in. In the thread, I shared a project to simplify doing that, but at the end of the day a command plug-in is what it is.
My approach is to use the API for (1) performance sensitive tasks that include (2) queries and (3) bulk operations. Queries with cmds or PyMEL can take an order of magnitude longer, and obviously don’t need undoing. Bulk operations on the other hand can require undo, but may sometimes get away with not bothering with it. Such as building a rig, where it may be ok to either delete the resulting hierarchy yourself, or start anew if it’s happening on a headless Maya or the like.
For anything interactive, like scene selection, cmds or PyMEL may suffice, and for times it doesn’t then the apiundo project has filled the remaining gaps on my end.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/571f4266-faf2-4990-9cd2-c58384bd9646%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.