top of page

Maya API 2019 vs 2022: What has Changed (Overview)?


ree

As newer versions of Maya are released almost every year, the API has taken a turn from the older versions that many studios still use. I have been working with Maya 2019 since its release and am still using it to this date. However, there seems to be a change in the new versions of Maya and also the adoption of Python 3.0. These changes would entice any studio to jump to the newer version in order to not be left behind with the latest updates.


With these updates comes changes in the API, and also a few modules, which would require any Pipeline Department to thoroughly examine almost every piece of code and update them to be able to work with the latest versions of Maya.


One major change in the Maya API in Maya 2022 is the introduction of the Maya API 2.0, which replaces the previous Maya API 1.0. Maya API 2.0 is a more modern and pythonic API that was designed to be more consistent and easier to use. Some of the major changes in the API include:

  • The use of python properties instead of getter/setter functions

  • More consistent naming conventions

  • The introduction of context managers for working with objects such as nodes and DG nodes

  • The use of the api package instead of the OpenMaya package


Here's an example of creating a transform node in Maya API 2.0:

import maya.api.OpenMaya as om2

# Create a transform node
transform = om2.MFnTransform()

# Set the translate values
transform.translate = om2.MVector(1.0, 2.0, 3.0)

# Get the translate values
print(transform.translate)

In Maya API 1.0, the same code would look like this:

import maya.OpenMaya as om1

# Create a transform function set
transform = om1.MFnTransform()

# Create a MTransformationMatrix
transformMatrix = transform.transformation()

# Create a MVector for the translation values
translation = om1.MVector(1.0, 2.0, 3.0)

# Set the translation of the MTransformationMatrix
transformMatrix.setTranslation(translation, om1.MSpace.kTransform)

# Set the transformation of the transform node
transform.setTransformation(transformMatrix)

# Get the translation values
translation = transformMatrix.getTranslation(om1.MSpace.kTransform)
print(translation)

The most notable difference is that in Maya API 2.0, use of properties and the pythonic nature of the code, making it more readable and easier to write.

Another change in the Maya API is the deprecation of some older and non-Pythonic functionality. For example, in Maya 2022 MAnimControl class is marked as deprecated and use of MAnimUtil or MTime class should be used.


# In maya 2019:
time = maya.MAnimControl.currentTime()

# In maya 2022:
time = maya.MAnimUtil.currentTime()

# Or
time = maya.MTime.uiTime()

Here are a few more examples of changes in the Maya API between Maya 2019 and Maya 2022:


MItDag class: In Maya 2022, the MItDag class was replaced by the api.MItDag class in Maya API 2.0. The new api.MItDag class uses a more pythonic iterator pattern, making it more consistent with python's built-in iterators.

# Maya 2019
import maya.OpenMaya as om1
it = om1.MItDag(om1.MItDag.kDepthFirst)
for i in range(it.count()):
    node = it.item()
    print(node.name())
    it.next()

# Maya 2022
import maya.api.OpenMaya as om2
it = om2.MItDag()
for node in it:
    print(node.name())


MSceneMessage class: The MSceneMessage class allows you to register callbacks to be notified of specific events in the Maya scene. In Maya 2022 the class was deprecated, and instead use the api.MMessage package

# Maya 2019
import maya.OpenMaya as om1
def myCallback(clientData):
    print("Scene was saved")

om1.MSceneMessage.addCallback(om1.MSceneMessage.kBeforeSave, myCallback)

# Maya 2022
import maya.api.OpenMaya as om2
def myCallback():
    print("Scene was saved")

om2.MMessage.addCallback(om2.MDGMessage.addBeforeSaveCallback, myCallback)


MGlobal class: In the new version of Maya, MGlobal class was updated and added many new functionality, such as creating a new instance of MDagModifier and MNodeModifier instead of storing them as global variables.

# Maya 2019
import maya.OpenMaya as om1
mDagMod = om1.MDagModifier()
mDagMod.createNode("transform")
mDagMod.doIt()

# Maya 2022
import maya.api.OpenMaya as om2
with om2.MDagModifier() as mDagMod:
    mDagMod.createNode("transform")

I recommend consulting the Maya documentation and the Maya API documentation for more information on the changes and new features in the Maya API, and experimenting with the examples provided in the documentation.


Please note that this is just a general overview and there are many other changes between these versions of Maya, which is highly recommended to have an extensive research and look at the documentation for more information.


Until next time.




2 Comments


vxhzkukkxfphsmomyw
Sep 11, 2023

Maya api 2.0 was not introduced in 2022, it's been around for ages and left incomplete too. Tons of missing classes.

Like
vxhzkukkxfphsmomyw
Sep 11, 2023
Replying to

a good example is MPxDeformer. Present on 1.0 but still missing on 2.0

Like

Contact me

so we can create creative & technical projects together
  • Github
  • LinkedIn
  • Instagram
  • Vimeo
  • YouTube
Join my mailing list

Thanks for submitting!

© 2023 by Dilen Shah

bottom of page