Differences Between Maya's C++ and Python APIs
 
 
 

The Maya Python API is not an exact copy of the C++ Maya API. We have made changes to the Python bindings for integration purposes.

No MString and MStringArray classes

We have removed the MString and MStringArray classes from the Maya Python API. Python already has a very robust string implementation which makes ours unnecessary.

No MStatus class

We have removed the MStatus class. Python exceptions must be used instead of MStatus. See Error Conditions and Exceptions versus MStatus for more information.

Void* Pointers

The Maya API makes use of void *pointers in several places including messages. In the Maya Python API, any Python object can be passed in place of a void* pointer.

Proxy Classes and Object Ownership

When creating a proxy class in a creator() function or any other function that returns the class to Maya, you must call OpenMayaMPx.asMPxPtr() on the new object. This call transfers ownership of the object to Maya. If this call is not made, then Python retains ownership and can dereference the object and destroy it even though Maya may have a pointer to it.

Commands with Flags must use an MSyntax

If a command tries to parse its flags directly from the MArgList passed to its doit() method, those flags will not be available for use when the command is used from Python. This is true regardless of whether the command was written in Python or C++.

To make flags available for use from Python the command must specify its syntax using an MSyntax object and parse the flags using the MArgParser or MArgDatabase classes.

Undo

It is possible to mix Maya Python API calls along with Maya command calls in the same script. Undoing the operations of such a script will not be correct if the Maya Python API calls modify the model and do not properly support undo using the MPxCommand class.

Modules versus Shared Libraries

When comparing these interfaces to the shared libraries we ship for the C++ Maya API, the only difference is a new OpenMayaMPx module. This module contains the bindings for any proxy or MPx class we provide.

Include files

The Maya API C++ include files are used to generate the bindings for the Maya Python API. These files are not required when programming with the Maya Python API but are useful to see what is included or excluded in the bindings, since not all items in the C++ API are scriptable.