Skip to content

Instantly share code, notes, and snippets.

@schworer
Created February 22, 2012 17:57
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save schworer/1886319 to your computer and use it in GitHub Desktop.
Save schworer/1886319 to your computer and use it in GitHub Desktop.
quick and dirty Maya Python undo decorator
from functools import wraps
from maya import cmds
def undo(func):
""" Puts the wrapped `func` into a single Maya Undo action, then
undoes it when the function enters the finally: block """
@wraps(func)
def _undofunc(*args, **kwargs):
try:
# start an undo chunk
cmds.undoInfo(ock=True)
return func(*args, **kwargs)
finally:
# after calling the func, end the undo chunk and undo
cmds.undoInfo(cck=True)
cmds.undo()
return _undofunc
from undo_dec import undo
from maya import cmds
@undo
def weird_func():
""" Creates a bunch of spheres and then gets rolled back """
rad = 0
for i in xrange(1000):
print i
rad += 0.2 * i
cmds.sphere(r=rad)
return rad
print weird_func()
@AtonLerin
Copy link

why is that "dirty" ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment