Tuesday 10 September 2019

Convert MEL to Python

Still converting MEL to python the oldschool way by deleting semi-colon here, adding a bracket there?

Pffffttt just use this!



import pymel.tools.mel2py as mel2py

print mel2py.mel2pyStr("""spaceLocator -p 0 0 0;""")


Output:


spaceLocator(p=(0, 0, 0))



Remember to add a cmds. to the start, because for some reason it doesn't add it on for you!

Now you can just replace 'spaceLocator -p 0 0 0;'  with any other MEL code that the script editor may spit out whilst you're Maya'ing and BAM insta-python!

Sure, it doesn't work for all cases but for other cases where you just want to copy & paste a handy addAttr line and can't be bothered to google it, it can come in handy and help speed things along.