Skip to content

Instantly share code, notes, and snippets.

@davidlatwe
Forked from schworer/undo_dec.py
Created November 23, 2017 07:29
Show Gist options
  • Save davidlatwe/76a15a597360d9ab24431d9d8b4b5942 to your computer and use it in GitHub Desktop.
Save davidlatwe/76a15a597360d9ab24431d9d8b4b5942 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment