• Fernanda

Passing mel scripts as python in Maya | Tech Art Bites

Updated: Oct 13, 2020

Have you ever tried reverse-engineering a MEL command in Maya only to find the python equivalent doesn't exist? That happens to me sometimes and it makes me so sad y'all. :(

There is a way to make it work, at the cost of making your script slower. So I'd avoid it unless you can't work around it.

We start by importing the mel library at the very top of our script:

import maya.mel as mel

And whenever we want to use a mel command we pass it as a string to mel.eval()

mel.eval('searchReplaceNames "left" "right" "selected";')

Note: if your mel arguments are being passed as strings inbetween " " (like above), you should use ' ' to define the beginning and end of your command string so Maya doesn't get confused.

You can still modify your arguments by using string concatenation. Just make sure the arguments are always passed as strings or make them into strings with the str() method.

mel.eval("rotate -r -rotate" + axis + " -ocp -os -fo " + amount + ";")

Anyways, remember that mel makes the script lower, so avoid it if you can! Specially if you run it in a loop, oh boy......


57 views0 comments

Recent Posts

See All

On the Subject of Resumes

Thank you again Sonia Michaels for providing some great material I could use for this post, and also @slizagna on twitter for a very helpful thread! Always keep your resume updated! I don't care if yo

Tech Art Tomfoolery: Unreal VR and glsl

Happy Tech Art Tuesday! My Youtube Channel has 200 subs now! That means I'm famous! I don't have a tutorial today but I did want to showcase some of the stuff I did this weekend. On Saturday morning I