py2melProc(function, returnType=None, procName=None, evaluateInputs=True, argTypes=None)

This is a work in progress. It generates and sources a mel procedure which wraps the passed python function. Theoretically useful for calling your python scripts in scenarios where Maya does not yet support python callbacks.

The function is inspected in order to generate a MEL procedure which relays its arguments on to the python function. However, Python features a very versatile argument structure whereas MEL does not.

  • python args with default values (keyword args) will be set to their MEL analogue, if it exists.

  • normal python args without default values default to strings. If ‘evaluteInputs’ is True, string arguments passed to the

    MEL wrapper proc will be evaluated as python code before being passed to your wrapped python function. This allows you to include a typecast in the string representing your arg:

    myWrapperProc( "Transform('persp')" );
  • *args : not yet implemented

  • **kwargs : not likely to be implemented


This can be a callable python object or the full, dotted path to the callable object as a string.

If passed as a python object, the object’s __name__ and __module__ attribute must point to a valid module where __name__ can be found.

If a string representing the python object is passed, it should include all packages and sub-modules, along with the function’s name: ‘’

Optional name of the mel procedure to be created. If None, the name of the function will be used.

If True (default), string arguments passed to the generated mel procedure will be evaluated as python code, allowing you to pass a more complex python objects as an argument. For example:

In python:
>>> import as py2mel
>>> def myFunc( arg ):
...    for x in arg:
...       print x
>>> py2mel.py2melProc( myFunc, procName='myFuncWrapper', evaluateInputs=True )
Then, in mel::
// execute the mel-to-python wrapper procedure myFuncWrapper(“[ 1, 2, 3]”);

the string “[1,2,3]” will be converted to a python list [1,2,3] before it is executed by the python function myFunc

Previous topic

Next topic


Core Modules

Other Modules

This Page