Skip to content

Instantly share code, notes, and snippets.

@justinfx
Created May 25, 2015
Embed
What would you like to do?
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

mikebourbeauart commented Jun 12, 2015

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