Get the action command of the previous custom tool used

58 views
Skip to first unread message

likage

unread,
Aug 10, 2018, 7:36:04 PM8/10/18
to Python Programming for Autodesk Maya
I have run a custom tool in a maya scene.
Say, if I am going to perform `z` (undo) via the keyboard, I would want to set the evaluation mode to be 'off' if the previous action is/ belongs to my custom tool.

I tried using `cmds.scriptJob(listJobs=True)`, while the entire contents are somewhat similar, before/ after using the undo key, with the exception of the last line, I am unable to script in a proper manner that will sets off the evaluation mode.

What any other ways can I proceed with this?

Marcus Ottosson

unread,
Aug 11, 2018, 2:37:28 AM8/11/18
to python_in...@googlegroups.com

Challenging!

I would want to set the evaluation mode to be ‘off’ if the previous action is/ belongs to my custom tool.

If you want to perform a specific command on undo, you could implement your tool as a Maya Command.

from maya import cmds
import myTool
myTool.install()
cmds.myTool()
# "Doing!"
# (press z)
# "Undoing.."

myTool.py

from maya import cmds
from maya.api import OpenMaya as om

class MyTool(om.MPxCommand):
    def doIt(self, args):
        print("Doing!")

    def undoIt(self):
        print("Undoing..")

    def redoIt(self):
        print("Redoing!")

    def isUndoable(self):
        # Without this, the above undoIt and redoIt will not be called
        return True

maya_useNewAPI = True

def initializePlugin(plugin):
    om.MFnPlugin(plugin).registerCommand("myTool", MyTool)

def uninitializePlugin(plugin):
    om.MFnPlugin(plugin).deregisterCommand("myTool")

def install():
    # Load command on `import myTool`
    cmds.loadPlugin(__file__)

If you put e.g. cmds.evaluationManager(mode="off") in the undoIt method, then whenever you undo this particular command, it’ll turn off (which is another word for DG) the evaluation manager.


--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/cd3aa750-fb11-4eb8-a5a3-3a7ab3225b2d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

likage

unread,
Aug 13, 2018, 8:42:06 PM8/13/18
to Python Programming for Autodesk Maya
Hi Marcus,

Many thanks for getting back! I will give it a try.
For my case and your solution, is making my tool the plugin the only way to go?

Additionally, regarding your code, where does "initializePlugin" and "uninitializePlugin" are called? Is it a default function that is handled by install()?
Reply all
Reply to author
Forward
0 new messages