#Description:
#Create a undo/redo callback using maya python api
#Usage:
#Call the undoRedoCallback function with "add" to create the undo/redo callbacks. Or call the
#undoRedoCallback function with "remove" as argument to remove the created callbacks.
#
#Info:
#Reference from undoRedoMsgCmd.cpp exemple
#By Rosenio Pinto
#kenio3d@gmail.com
import maya.OpenMaya as om
def undoTest(*args):
print 'Checking Undo callback'
def redoTest(*args):
print 'Checking ReDo callback'
def undoRedoCallback(arg):
global callbackIDs
undoStr = str('Undo')
redoStr = str('Redo')
Null = om.MObject()
if arg == 'add':
undoID = om.MEventMessage.addEventCallback(undoStr, undoTest, Null)
redoID = om.MEventMessage.addEventCallback(redoStr, redoTest, Null)
callbackIDs = [undoID, redoID]
elif arg == 'remove':
try:
for i in callbackIDs:
om.MEventMessage.removeCallback(i)
except:
print 'There is no ID to delete'
else:
print 'The argument must be "add" or "remove"'