Is there a way to convert mel to python?

3,768 views
Skip to first unread message

farsheed

unread,
Dec 18, 2007, 12:11:14 PM12/18/07
to python_inside_maya
I want to convert my previous mels to python. Is there any trusted
way?
Message has been deleted

trans...@gmail.com

unread,
Dec 21, 2007, 9:51:37 AM12/21/07
to python_inside_maya
perhaps you should try using

----
mel2py(melfile, outputDir=None, verbosity=0) source code

Convert a mel script into a python script.
----

command is part of Pymel module : http://www.highend3d.com/f/4844.html
you can also find some info here in this gropu about pymel.

I installed module today still havent tryed it out perhaps some
exp.users can comment on this command.

On 18 pro, 19:22, "farshid ashouri" <rodmena....@gmail.com> wrote:
> Just want to complete my question, I mean not converting by hand, line by
> line. A automated way, like a python script or pymel or ...?
> sorry for double post.
> Cheers.

Chadrik

unread,
Dec 21, 2007, 12:46:38 PM12/21/07
to python_inside_maya
yeah, mel2py will help you to convert the bulk of your code to python,
but you'll still have a lot of cleanup work. i've used it on many,
many scripts at luma and it generates working code 95% of the time,
but mel idioms differ greatly from those in python, so you will
definitely want to clean it up when you're done converting.

things that trip it up:
the mel command "python"
ui callback commands
"for" loops which increment multiple variables
ex. for ($i=0; $i<5, $j<20; $i++, $j+=2)
assignment of arrays by index when in mel, the index does not exist
ex. int $array[]; $array[5] = 1;

i still have not had much feedback on this module, so if you have
problems or suggestions be sure to pass them on.

-chad



On Dec 21, 9:51 am, "transfer...@gmail.com" <transfer...@gmail.com>
wrote:

hemant

unread,
Dec 29, 2007, 9:21:03 AM12/29/07
to python_inside_maya
hi

ya, u can write a complete Mel program in maya,
go through the billow link
http://cgkit.sourceforge.net/download.html

the python\maya plugin provide u this facility, u can directly source
the python program into the maya and u can write the complete MEL
programming into the python. on this link u found some PDF also so u
can refer them to details.


-hemant
Message has been deleted

farsheed Ashouri

unread,
Jan 25, 2008, 7:17:50 PM1/25/08
to python_inside_maya
Hi chad, Thanks for update. I've updated to pymel .76 and it rocks.
Could you please send us a brief and step by step tutorial about how
to convert mel to Python using mel2py?
Thanks in advance.

Chadrik

unread,
Jan 25, 2008, 7:52:05 PM1/25/08
to python_inside_maya
the new documentation in 0.7.6 provides a few examples.


to convert a single file. the second arg is the output dir:

import pymel.mel2py
pymel.mel2py.mel2py( '/Applications/Autodesk/maya2008/Maya.app/
Contents/scripts/others/ClipEdMenu.mel', '/lumaLocal/tmp' )


to bactch convert a whole directory:

import pymel.mel2py
pymel.mel2py.mel2pyBatch( '/Applications/Autodesk/maya2008/Maya.app/
Contents/scripts/others', '/lumaLocal/tmp' )

to convert just a string and return it as a string

print pymel.mel2py.mel2pyStr( """
int $i;
for ($i=0; $i<10; $i++) print $i;
""")


i wouldn't recommend running that second one, as there are almost
4,000 scripts in that directory.


farsheed, have you tried the new ScriptEditor yet? with that you can
just paste your script in and execute it and it will be converted to
python in the feedback window (fingers crossed).

-chad


farsheed Ashouri

unread,
Jan 25, 2008, 8:01:08 PM1/25/08
to python_inside_maya
How can I use new script editor?

farsheed Ashouri

unread,
Jan 25, 2008, 8:05:10 PM1/25/08
to python_inside_maya
Ok, Sorry. I found how to use it in docs. I'll try it now, Thanks.

Farsheed Ashouri

unread,
Jan 25, 2008, 8:14:59 PM1/25/08
to python_inside_maya
opps,Error ocured while using new script editor.
 
// Error: file: E:/Ducuments/maya/2008/scripts/scriptEditorPanel.mel line 1070: Object not found:
// Error: file: E:/Ducuments/maya/2008/scripts/scriptEditorPanel.mel line 1162: Error while parsing arguments.
 
 
I tried to open script editor after loading the plug-in but the script editor is empty. No menu, no output window.
 
 

Chadrik

unread,
Jan 25, 2008, 8:29:35 PM1/25/08
to python_inside_maya


try removing the scriptEditorPanel.mel and just load the plugin. make
sure that part works first.

Joel Ferreira

unread,
Jan 25, 2008, 8:35:12 PM1/25/08
to python_in...@googlegroups.com
And Python to mel? :P

On Jan 26, 2008 1:29 AM, Chadrik <cha...@gmail.com> wrote:
>
>
>
> try removing the scriptEditorPanel.mel and just load the plugin. make
> sure that part works first.
>

--
Joel Cunha Ferreira

Farsheed Ashouri

unread,
Jan 25, 2008, 8:50:53 PM1/25/08
to python_in...@googlegroups.com
But after removing the scriptEditorPanel.mel I havn't anything in feedback window. Also I have these errors in maya output:
swig/python detected a memory leak of type 'MGlobal *', no destructor found.
swig/python detected a memory leak of type 'MCallbackId *', no destructor found.
 
and this is maya script editor:

# Failed to register command: pymelScrollFieldReporter

// Error: line 1: (kFailure): Unexpected Internal Failure

# Traceback (most recent call last):

# File "E:/Ducuments/maya/2008/plug-ins/pymelScrollFieldReporter.py", line 455, in initializePlugin

# mplugin.registerCommand( kPluginCmdName, cmdCreator, syntaxCreator )

# RuntimeError: (kFailure): Unexpected Internal Failure //

// Warning: line 1: Failed to call script initialize function //

// Error: line 1: (pymelScrollFieldReporter) //

Chadrik

unread,
Jan 25, 2008, 8:57:18 PM1/25/08
to python_inside_maya
thx, that's what i needed. interesting that i don't get that on osx.
i'll have a look at it tonight on my pc. thanks for being my guinea
pig.

-chad

Chadrik

unread,
Feb 1, 2008, 7:27:30 PM2/1/08
to python_inside_maya

for you brave souls, there's another update to the script Editor
replacement in pymel 0.7.7, released today. i'm still not going to do
any full-blown announcement of this until i get more feedback on it so
let me know how it goes.

Farsheed Ashouri

unread,
Feb 1, 2008, 11:14:23 PM2/1/08
to python_in...@googlegroups.com
Hi chadrik and thanks for update.
This is my maya error both on maya 2k8 windows and maya 8.5 linux:

script editor output:

Cannot convert data of type int to type string[].
Start of trace: (file: C:/DriVe-E/Ducuments/maya/2008/scripts/scriptEditorPanel.mel, line 2329).
addScriptEditorPanel (command window: line 1).

maya output:

swig/python detected a memory leak of type 'MCallbackId *', no destructor found.

best regards, Farsheed.
Reply all
Reply to author
Forward
0 new messages