How to execute a globally defined MEL proc from Python/pyMel?

1,499 views
Skip to first unread message

Alan Fregtman

unread,
Jun 16, 2010, 2:45:07 PM6/16/10
to maya...@googlegroups.com
Hey guys,

I sense this is a really really noobish question. I apologize if that is so.

There's a global proc defined in a loaded .mel script (from a third
party) which I would like to call from my Python script in Maya.

I tried something like this:
import maya.cmds as cmds
cmds.SomeGlobalProc(arguments...)

and it didn't work, so I assume that cmds is only for original Maya
commands and not globally defined mel procedures, so... what's the
right syntax?

Any help appreciated.
Cheers,

-- Alan

CharlieWales

unread,
Jun 16, 2010, 3:07:51 PM6/16/10
to maya...@googlegroups.com
I think you need to import the maya.mel module in order to be able to run the eval mel command, passing the syntax of the mel procedure as a string:

Mel code to run:
myFuntion($var1, $var2)

Python syntax:

import maya.mel
maya.mel.eval('myFuntion(argument1,argument2)'

I don't know if there is a better/other way. Hope it helps.

2010/6/16 Alan Fregtman <alan.f...@gmail.com>

CharlieWales

unread,
Jun 16, 2010, 3:12:29 PM6/16/10
to maya...@googlegroups.com
There was a parenthesis missing in the python syntax above:

Valid code, passing the mel procedure with C style syntax:

import maya.mel
maya.mel.eval('myFuntion(argument1,argument2)')

or

import maya.mel
maya.mel.eval('myFuntion argument1 argument2')



2010/6/16 CharlieWales <charli...@gmail.com>

Alan Fregtman

unread,
Jun 16, 2010, 5:10:31 PM6/16/10
to maya...@googlegroups.com
Perfect! Can't believe I didn't think of "eval()".

Thank you, Charlie.

-- Alan

Sagroth

unread,
Jun 18, 2010, 7:14:36 PM6/18/10
to maya_he3d
I little bit cleaner, in my opinion, to use it like this:

from maya.mel import eval
eval( 'myGlobalProc();' )
Reply all
Reply to author
Forward
0 new messages