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 now we have a handle of getting a selection, or building an MSelectionList()
to get MObjects to manipulate in scene.
Now another big part of our day is creating nodes / adding or removing
attributes / querying attributes values / connecting or disconnecting attributes.
Below might look familiar those of you using cmds a lot;
Yes it is true that we’re about to convert this into more lines using om2.
And yes I still do a lot of prototyping in cmds when mashing stuff together
in the script editor, but for reuse tools, I will most likely convert those scripts to om2,
even the ones that might not see a lot of benefit speed wise, as it’s just
good practise and I find it fun to do shrug.
So what about this:
”# some plugs are compounds, some are arrays, some are floats / bool / shorts / double etc”
If you’re confused what kind you’re dealing with you can use Maya’s nodeEditor
to try to figure it out.
An MPlug has a couple methods to help out.
The main difference between an Array and a Compound being;
Arrays uses physical / logical indices
Compounds have child(x)
Lets look at this in code:
Finally it’s probably important to know the difference between a logical index
and a physical one… from the docs… yes the info is all there :P
“This method will find and return a plug with the given logical index.
The logical index is the sparse array index used in MEL scripts.
If a plug does not exist at the given Index, Maya will create a plug at that index.
This is not the case with elementByPhysicalIndex(). If needed, elementByLogicalIndex
can be used to expand an array plug on a node.
It is important to note that Maya assumes that all such plugs serve a purpose and it will not free non-networked
plugs that result from such an array expansion.”
“This method will find and return a plug with the given physical index.
The index can range from 0 to numElements() - 1. This function is particularly
useful for iteration through the element plugs of an array plug. It is
equivalent to operator  (int) This method is only valid for array plugs.
If the returned plug is networked, the networked plug will be returned.
Otherwise, a non-networked plug will be returned.”