Skip to content

Instantly share code, notes, and snippets.

Created May 25, 2015 10:40
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Example of a repeatable command decorate, for Maya (maya.cmds)
Original example reformatted from:
python_inside_maya 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)
cmds.repeatLast(ac=_repeat_command_str, acl=function.__name__)
except RuntimeError:
return ret
return wrapper
def example():
print "example()"
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