Happy to report this has worked surprisingly well!
Using it primarily with the modifier, like in the example above. In fact, I
subclassed the modifier to automatically add itself to the undo queue when
used.
from maya.api import OpenMaya as omimport apiundo
class DagModifier(om.MDagModifier):
def __init__(self, *args, **kwargs):
super(DagModifier, self).__init__(*args, **kwargs)
apiundo.commit(self.undoIt, self.doIt)
mod = DagModifier()
mod.createNode("transform")
mod.doIt()
At first it seemed a little too simple to actually work in practice, but
sometimes the simple things work best, and so it’s been!
There is however one caveat that I’ve encountered so far with apiundo in
general, which is that undoing the creation of a node derived from a custom
plug-in prevents that plug-in from being unloaded; even after calls to
cmds.flushUndo() and cmds.file(new=True). I suspect the instance of the
Maya command is being held in memory by Python along with the reference to
the modifier responsible for creating the node, but have yet to thoroughly
investigate. I did try storing references to functions with weakref.ref(),
but even that didn’t make a difference.
The “workaround” is restarting Maya, which is somewhat of a pain so any
help with this would be much appreciated.
Accepting pull-requests!
- https://github.com/mottosso/apiundo
Ps. The above example works, but is somewhat simplified. Don’t forget the
edge case of it being added to the undo-queue even withing calling doIt,
and if you do subclass doIt instead, don’t forget to add the
superclass-doIt to the undo queue.
On 25 March 2018 at 12:54, Marcus Ottosson <[email protected]> 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODVpyXnhNxSXf_KkP912Qwyo%2BTA7UL7Q%3D92fDYdwy-Xxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.