Пример #1
0
    def wrapper(*args, **kwargs):
        global _REPEATABLE_FUNC
        _REPEATABLE_FUNC = partial(func, *args, **kwargs)

        result = func(*args, **kwargs)

        try:
            cmds.repeatLast(ac=_REPEAT_COMMAND, acl=func.__name__)
        except RuntimeError:
            pass

        return result
Пример #2
0
 def mel_handler(self, input_str):
     prev_chunk = cmds.undoInfo(q=True, chunkName=True)
     cmds.undoInfo(openChunk=True)
     try:
         execInMain(partial(mel.eval, input_str))
         cmds.repeatLast(addCommand=input_str)
         cmds.undoInfo(closeChunk=True)
     except:
         cmds.undoInfo(closeChunk=True)
         if not cmds.undoInfo(q=True, chunkName=True) == prev_chunk:
             cmds.undo()
         raise
Пример #3
0
 def py_handler(self, input_str):
     prev_chunk = cmds.undoInfo(q=True, chunkName=True)
     cmds.undoInfo(openChunk=True)
     try:
         execInMain(input_str)
         setattr(__main__, "last_py_cmd", input_str)
         cmds.repeatLast(addCommand='python("execInMain(last_py_cmd)")')
         cmds.undoInfo(closeChunk=True)
     except:
         cmds.undoInfo(closeChunk=True)
         if not cmds.undoInfo(q=True, chunkName=True) == prev_chunk:
             cmds.undo()
         raise
Пример #4
0
	def stacksHandlerCall(*args, **kwargs):
		"""
		This decorator is used to handle various Maya stacks.

		:return: Python object. ( Python )
		"""

		cmds.undoInfo(openChunk=True)
		value = object(*args, **kwargs)
		cmds.undoInfo(closeChunk=True)
		# Maya produces a weird command error if not wrapped here.
		try:
			cmds.repeatLast(addCommand="python(\"import %s; %s.%s()\")" % (__name__, __name__, object.__name__), addCommandLabel=object.__name__)
		except:
			pass
		return value
Пример #5
0
	def stacksHandlerCall(*args, **kwargs):
		"""
		Handles Maya stacks.

		:return: Python object.
		:rtype: object
		"""

		cmds.undoInfo(openChunk=True)
		value = object(*args, **kwargs)
		cmds.undoInfo(closeChunk=True)
		# Maya produces a weird command error if not wrapped here.
		try:
			cmds.repeatLast(addCommand="python(\"import %s; %s.%s()\")" % (__name__, __name__, object.__name__), addCommandLabel=object.__name__)
		except:
			pass
		return value
Пример #6
0
def register_repeat_last(action):
    """Register the action in repeatLast to ensure the RepeatLast hotkey works

    Args:
        action (action.Action): Action wigdet instance

    Returns:
        int: 0

    """
    command = action.process_command()
    command = command.replace("\n", "; ")
    # Register command to Maya (mel)
    cmds.repeatLast(addCommand='python("{}")'.format(command),
                    addCommandLabel=action.label)

    return 0
    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
Пример #8
0
    def wrapper(*args, **kwargs):
        parameters = ''
        if args:
            parameters = ', '.join([str(i) for i in args])
        if kwargs:
            kwargs_parameters = [
                '='.join([str(key), str(value)])
                for key, value in kwargs.iteritems()
            ]
            parameters += ', '.join(kwargs_parameters)

        cmds.evalDeferred('import {}'.format(func.__module__))
        command = 'python("{}.{}({})")'.format(func.__module__, func.__name__, parameters)
        result = func(*args, **kwargs)
        try:
            cmds.repeatLast(ac=command, acl=func.__name__)
        except RuntimeError:
            pass
        return result
Пример #9
0
    def decoratorCode(*args, **kwargs):
        functionReturn = None
        argString = ''
        if args:
            for each in args:
                argString += str(each) + ', '

        if kwargs:
            for key, item in kwargs.iteritems():
                argString += str(key) + '=' + str(item) + ', '

        commandToRepeat = 'python("' + __name__ + '.' + function.__name__ + '(' + argString + ')")'

        functionReturn = function(*args, **kwargs)
        try:
            mc.repeatLast(ac=commandToRepeat, acl=function.__name__)
        except:
            pass

        return functionReturn
Пример #10
0
def repeatLast(*args, **kwargs):
    if len(args):
        doPassSelf = kwargs.pop('passSelf', False)
    else:
        doPassSelf = False
    for key in [
            'ac', 'acl', 'addCommand', 'addCommandLabel', 'cl', 'cnl',
            'commandList', 'commandNameList'
    ]:
        try:
            cb = kwargs[key]
            if callable(cb):
                kwargs[key] = _factories.makeUICallback(cb, args, doPassSelf)
        except KeyError:
            pass
    res = cmds.repeatLast(*args, **kwargs)
    return res
Пример #11
0
 def __call__(self):
     cmds.repeatLast(addCommand=self.mel, addCommandLabel=self.label)
     self.cmd()
Пример #12
0
 def _clean_dotbox_repeatable_history():
     repeat_history = cmds.repeatLast(query=True, commandNameList=True)
     for command in Repeatable.history.values()[:]:
         if command.label not in repeat_history:
             del Repeatable.history[command.id_]