How to call mel procedure in python??

4,479 views
Skip to first unread message

Yeah.Y

unread,
Mar 24, 2008, 10:29:59 AM3/24/08
to python_inside_maya
I am building a GUI in python, and there are many useful mel scripts I
dont want to write them again in python.
Is there a method or command can call mel in python??

Thanks for helping!!

Best Regards!!
Yeah.Y

yury nedelin

unread,
Mar 24, 2008, 11:25:30 AM3/24/08
to python_in...@googlegroups.com
yes you can.

just as you can import the maya commands you can import the Mel scripts

try  doing this

import maya.mel as mm
mm.eval("myMelScript;")

here is the part of the help docs from maya

Calling MEL from Python

To call MEL from Python, use the maya.mel.eval() function. It can do a better job of conversion than the MEL python command since Python has more flexible type support.

You must import the maya.mel module to use this command; that is:

import maya.mel as mm
mm.eval("polySphere;")


yury

Farsheed Ashouri

unread,
Mar 24, 2008, 12:09:46 PM3/24/08
to python_in...@googlegroups.com
Or you can convert them to python with Pymel. Search topics for this.

Yeah.Y

unread,
Mar 24, 2008, 12:21:14 PM3/24/08
to python_inside_maya
Thanksssss a lot,
with your help, I try it out, but another weird thing in pymel happen:

the code below, notice the "text(label = "Set X Y Z Range Values")"

#error: 'unicode' object is not callable

I dont know what's going on. if i dont use pymel, things gonna be all
right
Please help, thanks!!

#################################
dWin = window(title="Disperser", wh = (256, 256))
columnLayout()
button(label = "Disperse Selected!", command="disperse()")
text(label = "Set X Y Z Range Values")
rangeField = floatFieldGrp(numberOfFields=3)
showWindow(dWin)
#################################

Chadrik

unread,
Mar 24, 2008, 12:49:07 PM3/24/08
to python_inside_maya
using pymel is going to save you a *lot* of time when calling mel.
the alternative is a string formatting nightmare, especially if you
are passing arguments. with pymel you can call your mel script just
as you would any other python function.

instead of :
>>> mm.eval("myMelScript;")

you can just do:
>>> mel.myScript()

passed arguments will be formatted as well

-chad

Yeah.Y

unread,
Mar 24, 2008, 10:02:17 PM3/24/08
to python_inside_maya
Oh, that's awesome, I try it out and found it pretty cool
Thanks again Chadrik :-)

Best Regards!!
Yeah.Y
Reply all
Reply to author
Forward
0 new messages