Skip to content

Instantly share code, notes, and snippets.

@hogjonny
Created June 13, 2013 15:08
Show Gist options
  • Save hogjonny/5774453 to your computer and use it in GitHub Desktop.
Save hogjonny/5774453 to your computer and use it in GitHub Desktop.
This is a block of code, which creates a Class for managing Undo chunking in Autodesk Maya, Python scripts. I have tested this in my Maya 2011 setup, and it works great. This code snippet came from Rob Galanakis, via Tech-artist.org forums: http://tech-artists.org/forum/showthread.php?2522-Undo-in-Maya-(Mel-Python-Execution)
import maya.cmds as mc
###########################################################################
## This wraps commands in a maya UndoContext
# -------------------------------------------------------------------------
class UndoContext(object):
def __enter__(self):
mc.undoInfo(openChunk=True)
def __exit__(self, *exc_info):
mc.undoInfo(closeChunk=True)
## This is how you call to the UndoContext()
with UndoContext():
#... your code here....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment