All code here is provided as is without support.
Use at your own risk! These posts assume you have some knowledge of import/running python script in maya.
If Gifs/Images are not displaying in Chrome try a different browser.
So I’ve selected all the default camera’s in scene and want to access the
list of selected items in scene.
So the most noticeable difference here is;
cmds.ls() returns a python list
om2.MGlobal.getActiveSelectionList() returns an MSelectionList()
And since cmds returns a python list of strings you can very quickly use:
But what the heck do you do with an MSelectionList()?
We can’t do this on the MSelection list?! Well we have to use the
MSelectionList.length() arg and iter using the .getDependNode() method. eg:
Since you’ve most likely just come from the reading the API
post lets look at the docs for the getDependNode(x) method.
You can clearly see it says `Returns: MObject’ so you now know what is being
returned by this method!
In the example above I used it to create an instance of the MFnDependencyNode
and print the name.
And this is now most likely starting to shine a light on the crux of the
differences for you between cmds and om2.
om2 is a little lower level. You’re dealing more with python classes / function
sets now, and you’re having to handle your MObjects, MPlugs etc so you have
to keep track of your types and what accepts/returns what.