Hey Michael,

There was a thread recently about the API and undo.

   - https://groups.google.com/forum/#!topic/python_inside_maya/fqX9mNfg5j0

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 <https://github.com/mottosso/apiundo> 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.
​

On 10 April 2018 at 00:52, Michael Boon <boons...@gmail.com> wrote:

> Yeah I was worried that might be the only way to do it without PyMel or
> cmds. I imagine there are cases where the PyMel solution would be slow
> enough to warrant writing a plugin command like that.
>
>
> On Tuesday, 10 April 2018 02:52:45 UTC+10, justin hidair wrote:
>>
>> how about dat ? It requires a command tho .
>>
>> 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)
>>         sList = om.MSelectionList()
>>         sList.add((meshFn.getPath(), compObj))
>>         om.MGlobal.setActiveSelectionList(sList)
>>
>>
>>
>> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/python_inside_maya/571f4266-faf2-4990-9cd2-
> c58384bd9646%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/571f4266-faf2-4990-9cd2-c58384bd9646%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODBqHxZwuoNh940Q4U5oLFzMuLc5z-%3DSg-zGThp1cSy9w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to