Open Maya (Maya API 2.0) learning curve

Hey everyone !
I got convinced by system bot to start a new topic so here I am ! :smiley:

I started to learn using Open Maya after receiving feedback from a tech artist that reviewed a technical test that I did for it’s company.

He told me that using this new API is the better way of working when dealing with sub object operations.

Am I the only that find this API worse than the old api with cmds and stuff ? In term of documentation the old one was so much better and easier to learn I feel !

That’s a newbie impressions, I’m curious to know about yours :grin:

the API1.0 and API2.0 documentation is way worse as the cmds documentation is one of the easiest ones to understand for maya coding.

in my experience it takes a lot more reading and understanding before you are on your way to test things out. examples are difficult to find and most of the time not exactly what you need, but if you give it some time you will get used to it.

api1 is the most inclusive as its just a direct wrapper for th c++ code but in that way it makes dealing with pointers and references a lot more difficult and is a big step up from the cmds commands
api2 is a bit better but does not include everything, so there are times where you are well on your way creating a plugin or a script to find out its not possible through api2 alone, or when you expect to use the default int/float from python as an argument but need an MTime() object its not always immediatly clear from the error message.

however, i have noticed that most code documentation is more like these setups than the cmds documentation. so once you get used to it you it will help you much more later on.

On the other hand its also the reasons why there are so many wrappers around the cmds pipeline to leverage the Api setup. pyMel, Omx, Cmdx and cmdWrapper all use similar setups as cmds but will return you objects instead of strings which is a lot more powerfull to work with.

1 Like

Hello Peerke ! Thanks for you insights :grinning_face_with_smiling_eyes:

I’ve heard that most documentation were similar to the Open Maya ones as well which makes me want to recreate those documentations by myself :sob: I feel like more budget should go to documentation it’s so important I feel.

Open Maya says that you should avoid using cmds together om but does it means that generally a tool made with the api 2.0 is only made with it ? Or people mix the two anyway ?

There is still so much to learn for me about scripting so sorry if it’s basic questions :laughing:

i feel in general it is always mixed when it comes to scripting and making tools ‘except’ when you make plugins or nodes.

cmds does a lot of things in a neat and clear way that is very difficult to do with just openmaya and cmds already takes care of a lot of edgecases so mixing them up is in my opinion the best way to go

for example getting the matrix of an object in maya using OpenMaya would be something like this:

from maya import cmds
from maya.api import OpenMaya

nodeName = "pCube1"
selectrionList = OpenMaya.MGlobal.getSelectionListByName(nodeName)
dagNode = selectrionList.getDagPath(0)
transform = OpenMaya.MFnTransform(dagNode)
transformationMatrix = transform.transformation()
resultMatrix = transformationMatrix.asMatrix()

while if you do a mix of cmds and openmaya you can get rid of a lot of bloat you dont really need

from maya import cmds
from maya.api import OpenMaya

nodeName = "pCube1"
matrixList = cmds.xform(nodeName, query=1, worldSpace=1, matrix=1)
resultMatrix = OpenMaya.MMatrix(matrixList)

depending on how you mix the 2 you can even make it more readable and in some cases even faster then just sticking with 1 solution. note that these examples are used as you probably want to convert a matrix to its object as its easier to get positional or rotational data or just do basic matrix math with

1 Like

That’s good to know thank you !

I still have to get the pros and cons of each API but that will come from experience I’m sure :grinning_face_with_smiling_eyes:

api1 is sortof a direct conversion of the C++ codebase,
in this case you will get objects back from the code so it holds a lot more data then the usual basic string, list, int, etc. data you get back from cmds but it comes with the caveat that it deals with the code as if its c++ more then python.

in most cases if you give an argument to a python function you expect to work with the data and recieve a returned element of the function to have the altered data
in c++ you have pointers and references which directly alter the inputdata without the necessity to return these arguments (over simplification on pointers and references but the simplest analogy i can make for now) and in some cases it deals with more complex data then we can easily provide from python so we need to make use of the mscriptUtil to provide these to us.

api2 is a more pythonic conversion of the c++ library and (in most cases) deals with the data as you would expect a python object/function to work, the downside here is that not all of the C++ library is converted to this setup and you will find instances that you will need to revert back to api1 or cmds to complete the code.

i am writing this really simplified and i know it will piss off some programmers on my terminology but hopefully this helps :slight_smile:

1 Like