Skip to content

Instantly share code, notes, and snippets.

@justinfx
Created May 25, 2015 10:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinfx/f86320b6d9b567e6b8e2 to your computer and use it in GitHub Desktop.
Save justinfx/f86320b6d9b567e6b8e2 to your computer and use it in GitHub Desktop.
Example of a repeatable command decorate, for Maya (maya.cmds)
"""
Original example reformatted from:
http://blog.3dkris.com/2011/08/python-in-maya-how-to-make-commands.html
python_inside_maya discussion:
https://groups.google.com/d/topic/python_inside_maya/xfuCYBO6aLg/discussion
"""
import maya.cmds as cmds
_repeat_command_str = 'python("%s._repeat_command()")' % __name__
_repeat_function = None
_args = None
_kwargs = None
def _repeat_command():
if _repeat_function is not None:
_repeat_function(*_args, **_kwargs)
def repeatable(function):
def wrapper(*args, **kwargs):
global _repeat_function
global _args
global _kwargs
_repeat_function = function
_args = args
_kwargs = kwargs
ret = function(*args, **kwargs)
try:
cmds.repeatLast(ac=_repeat_command_str, acl=function.__name__)
except RuntimeError:
pass
return ret
return wrapper
@repeatable
def example():
print "example()"
@mikebourbeauart
Copy link

I keep getting this error when I run the script:

Error: line 1: name 'main' is not defined
Traceback (most recent call last):
File "", line 1, in
NameError: name 'main' is not defined

main has the double underscores and quotation marks on either side. github seems to be using that syntax to bold it :/

Any thoughts on what the problem could be?

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