-
-
Save davidlatwe/76a15a597360d9ab24431d9d8b4b5942 to your computer and use it in GitHub Desktop.
quick and dirty Maya Python undo decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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