Hey Marcus,

For starters you shouldn't be popping undo/redo methods otherwise it
immediately gets lost after you undo.
Ideally, you don't want to be managing your own stack anyway since the
command object is already on the Maya stack you can have it own the
relevant undo/redo method, the only question is how to ingest it in the
least offensive way possible.

Here is one possible way of doing it:

# modify your code with the following
import _ctypes

class apiUndo(om.MPxCommand):
    def doIt(self, args):
        # using asDouble, asInt fails here probably because id is too large
        undo_id = long(args.asDouble(0))
        redo_id = long(args.asDouble(1))
        self.undo = _ctypes.PyObj_FromPtr(undo_id)
        self.redo = _ctypes.PyObj_FromPtr(redo_id)

    def undoIt(self):
        self.displayInfo("Undoing..")
        self.undo()

    def redoIt(self):
        self.displayInfo("Redoing..")
        self.redo()


# in maya define undo/redo somehow
def undo():
    print 'Undo Me'

def redo():
    print 'Redo Me'

# call command directly
cmds.apiUndo(id(undo), id(redo))


Cheers!


On Sun, Mar 25, 2018 at 7:54 AM, Marcus Ottosson <konstrukt...@gmail.com>
wrote:

> I’ve put together my impression of what was mentioned in the cult of rig
> video posted earlier.
>
>    - https://github.com/mottosso/apiundo
>
> *Example*
>
> from maya.api import OpenMaya as omimport apiundo
>
> mod = om.MDagModifier()
> mod.createNode("transform")
> mod.doIt()
>
> apiundo.commit(
>     undo=mod.undoIt,
>     redo=mod.doIt
> )
>
> However I’m struggling to properly merge it with Maya’s native undo queue;
> the main contender is redo. Natively, once something has been redone, you
> can undo it again. I haven’t yet managed to find a generic method of
> achieving this. Other than that it remains largely untested. Could use some
> help on this one.
> ​
>
> --
> 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/CAFRtmOAmLLdnKHFW%3DzQPuZMDu67XNhH8QYHmPwXme-
> zfhBsQGA%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAmLLdnKHFW%3DzQPuZMDu67XNhH8QYHmPwXme-zfhBsQGA%40mail.gmail.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/CAPCVZ5Pt%2BjJpe6hh9%3DTRMb9hGMmi2pjBFL0hurcTxtPSCQHZ5w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to