Last active
October 12, 2021 13:11
-
-
Save BigRoy/01ecf1b77c26b1583620 to your computer and use it in GitHub Desktop.
Parse a Maya MEL command string into the command name, args and kwargs.
This file contains hidden or 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
def parse_mel_cmd(melStr): | |
"""Return the command, args and kwargs for a MEL command string""" | |
# Get python variant and split of pymel import line | |
import pymel.tools.mel2py as mel2py | |
pyCmd = mel2py.mel2pyStr(melStr) | |
pyCmd = pyCmd.splitlines()[1] | |
cmd, arguments = pyCmd.split("(", 1) | |
args, kwargs = eval("dummy" + "".join(pyCmd.partition("(")[1:]), {}, dict(dummy=lambda *x, **y: (x, y))) | |
return {'cmd': cmd, | |
'args': args, | |
'kwargs': kwargs} | |
print parse_mel_cmd('setAttr |balloon_model:balloon_GRP.translate -type "double3" -13.076091 21.600848 -0.975668;') | |
# {'cmd': 'setAttr', | |
# 'args': ('|balloon_model:balloon_GRP.translate', -13.076091, 21.600848, -0.975668), | |
# 'kwargs': {'type': 'double3'}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment