The Maya Python API 2.0 is a new version of the Maya Python API which provides a more Pythonic workflow and improved performance. Both the new and old APIs can co-exist in the same script but objects from the two different APIs cannot be used interchangeably.
The Python API 2.0 has a number of advantages over the original API:
The new Python API modules are found in maya.api. For example:
import maya.api.OpenMaya as om
Module names are the same as in the old API with the exception that the proxy classes (i.e. those beginning with MPx) no longer have their own module but reside in the same modules as other related classes. This more closely resembles the C++ API.
Class names are the same as in the old Python API and the C++ API. Method names are mostly the same with some differences where it affects the workflow. Some methods which simply get or set values on an object have been replaced with Python object attributes.
New and old API classes can be used within the same script, but their objects are not interchangeable. Thus, you can do this:
import maya.api.OpenMaya as newOM import maya.OpenMaya as oldOM newAttrObj = newOM.MObject() oldNodeObj = oldOM.MObject() ... newAttrFn = newOM.MFnAttribute(newAttrObj) oldNodeFn = oldOM.MFnDependencyNode(oldNodeObj) # OKAY: Print names from old and new function sets. print("Attribute name is %s.%s" % (oldNodeFn.name(), newAttrFn.name))
but not this:
import maya.api.OpenMaya as newOM import maya.OpenMaya as oldOM newAttrObj = newOM.MObject() oldNodeObj = oldOM.MObject() ... # BAD: Passing an old API MObject to a new API method. newPlug = newOM.MPlug(oldNodeObj, newAttrObj)
Given that the class and method names are mostly identical between the two APIs there is a lot of potential for confusion so it's best not to mix them if you can avoid it.
When writing a plugin which uses the new API, the plugin must define a function called maya_useNewAPI so that Maya will know to pass it objects from the new API rather than the old one. E.g:
def maya_useNewAPI(): pass
We encourage users to provide feedback on this new Python API through the online Suggestion site available from the Maya Help Menu and through the Autodesk Developer Network.
The following classes have been implemented in the new API. Clicking on the class name will display its documentation. The class documentation focuses primarily on the parameter and return values of the methods. For additional information on the class you should refer to the documentation of the corresponding C++ class in the main Maya API documentation.
© 2011 Autodesk, Inc. All rights reserved.