Differences between the C++ Maya API and Maya Python API
 
 
 

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 Arguments must use an MSyntax

In C++, it is possible to use the argument parameter of MPxCommand::doIt() to find which arguments have been entered. In Python, this does not work. Instead, you must use the MSyntax and MArgParser classes to support arguments within a scripted MPxCommand.

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.