Hi, I've created a toolbox with a bunch of buttons written in MEL. I'm wondering if I can port that window into Python without having to completely rewrite all the buttons, just re-code the GUI. And if so where should I go to learn how to create a Phython toolbox, I checked the Maya help and didn't really see a tutorial in there.
"This function takes a string which contains MEL code and evaluates it using the MEL interpreter. The result is converted into a Python data type and is returned. If an error occurs during the execution of the MEL script, a Python exception is raised with the appropriate error message."
Inside some MEL file. Lets call it MELFile.mel proc MELFunction() {}
Now in Python file.
First we need to source the MEL script.
mel.eval('source "C:/SomeFolder/MELFile.mel" ') Note apostrophe and quotation. mel.eval("MELFunction") This will call function from MEL.
Also make sure you import MEL at the top of the everything. import maya.mel as mel
Also I forgot here is the Maya Python API. When you click on each function there should be a pretty good tutorial at the bottom. For the GUI you can start with the window() function. There are multiple buttons aswel like radioButton(), button(), etc. Just play around with it, it really gets easy after a while. http://help.autodesk.com/cloudhelp/2017/CHS/Maya-Tech-Docs/CommandsPython/
It will convert MEL code into Python for you. I used it a lot when I was first teaching myself Python so I could compare one language to the other. It's not perfect, but that is to be expected with any translator, and it certainly gives a person who doesn't know Python a starting point. Hope it helps!
Replies
http://help.autodesk.com/cloudhelp/2017/CHS/Maya-Tech-Docs/CommandsPython/eval.html
"This function takes a string which contains MEL code and evaluates it using the MEL interpreter. The result is converted into a Python data type and is returned. If an error occurs during the execution of the MEL script, a Python exception is raised with the appropriate error message."
Inside some MEL file. Lets call it MELFile.mel
proc MELFunction()
{}
Now in Python file.
First we need to source the MEL script.
mel.eval('source "C:/SomeFolder/MELFile.mel" ') Note apostrophe and quotation.
mel.eval("MELFunction") This will call function from MEL.
Also make sure you import MEL at the top of the everything.
import maya.mel as mel
For the GUI you can start with the window() function. There are multiple buttons aswel like radioButton(), button(), etc. Just play around with it, it really gets easy after a while.
http://help.autodesk.com/cloudhelp/2017/CHS/Maya-Tech-Docs/CommandsPython/
You might give this free script a whirl:
https://www.highend3d.com/maya/script/ezmel2python-for-maya
It will convert MEL code into Python for you. I used it a lot when I was first teaching myself Python so I could compare one language to the other. It's not perfect, but that is to be expected with any translator, and it certainly gives a person who doesn't know Python a starting point.
Hope it helps!