om2-BeginnersGuide 01 - Reading the API
Disclaimer:
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 you’re looking to start breaking into some om2? Good. Lets dive in! Being able to read the docs is important. So lets take a quick nosey at those first.

OpenMaya API Docs 2018

APIom2

Depending on what you’re working on you’re going to be in one of these 4 modules.

For now I’ll stay in OpenMaya to cover the basics.

I was going to do a big screen shot with all kinds of arrows etc, but I think it’s best if you open up a this page HERE and follow along the headers as I break down what each section represents.


OpenMaya.MFnDependencyNode Class Reference
------------------------------------------

Class Description
--------------------------------------------------------------------

    Function set for operating on dependency nodes

Gives you an over view of what this class does / is.
In this instance we’re looking at the MFnDependencyNode class which if you’d read the above links you can see has the MFn naming showing it’s a function set, and the class desc states as much


Base Class
--------------------------------------------------------------------
    *MFnBase*

Is what this class inherits from.
So anything in the baseClass should be available to you for use from this class too.
Clicking on this will take you through that classes page for further info.


Constructors
--------------------------------------------------------------------
Signature Parameters Description
MFnDependencyNode()   Default constructor. Returns a new MFnDependencyNode function set with no node attached.
MFnDependencyNode(node) object - MObject Returns a new MFnDependencyNode function set, attached to the specified Maya node.

This is the info you need to know when constructing an instance of the class for use in your code. Do you need to pass in an MMatrix? and MFloatMatrix? MObject? eg:

    from maya.api import OpenMaya as om2
    # Construct MFnDependencyNode that isn't attached to any MOBject.
    myMFnDep = om2.MFnDependencyNode()
    
    # Construct MFnDependencyNode that is attached to any MOBject
    myMObj = om2.MObject()
    myMFnDep = om2.MFnDependencyNode(myMObj)
    

Inheritance diagram for OpenMaya.MfnDependencyNode
--------------------------------------------------------------------

This shows you how this class sits in the API, what it inherits, and what inherits it. Click to expand that view.


Public Member Functions
--------------------------------------------------------------------
    __init__ ()
    absoluteName()
    addAttribute() ...

These are all the methods in the class that you can use on the MObject (assigned to the function set).

Each of these have their own documentation sections below and can be clicked on for reference.


Public Member Functions inherited from ...
--------------------------------------------------------------------

These are all the methods in the class that come from the base class for use.


Static Public Member Functions
--------------------------------------------------------------------
    allocateFlag()
    classification() ...

“A static member function is a special member function, which is used to access only static data members”


Static Public Attributes
--------------------------------------------------------------------

Bunch of default attributes set on nodes etc.


Properties
--------------------------------------------------------------------
    isDefaultNode
    isFromReferencedFile
    isLocked ...

Used the same as python properties myObject.property with no ()


    MORE INFO: Public Member Function:
    ----------------------------------------------------------------    

    >>Lets look at the findPlug() method's documentation a little closer.

    OpenMaya.MFnDependencyNode.findPlug()  
    Returns a plug for the given attribute.
    Signature:      findPlug(attr, wantNetworkedPlug)
    Parameters:     attr - string or MObject
                    wantNetworkedPlug - bool
    Returns:        MPlug
    Description: Returns a plug for the given attribute, which may be specified either by name or by MObject.

So looking at this we can see that findPlug() takes 2 input args. A string OR an MObject can be used for the attr arg, and a boolean is required for the wantedNetworkedPlug or not.
And we know that what is returned will be an MPlug. eg:

    from maya.api import OpenMaya as om2
    
    currentSelected = om2.MGlobal.getActiveSelectionlist()  # -> MSelectionList()
    firstSelected = currentSelected.getDependNode(0)        # -> MObject()
    myMFnDep = om2.MFnDependencyNode(firstSelected)         # -> MFnDependencyNode() functionSet
    myPlug = myMFnDep.findPlug("myAttrName", False)         # -> MPlug()
    

So that should cover pretty much the basics for you to start being able to get around the API documentation as there are a LOT of classes to learn and you’re not going to remember everything there is so you should know how to figure things out from the docs.


You’re going to need to read the following (even if you don’t make sense of it! Just read them). Gets your brain starting to fire up some dots to connect as we proceed.

You need to know this because you’re not just calling cmds and getting a string or a list of strings anymore. You’re dealing directly with MObjects / Function sets / Iterators etc that resembles the C++ API !

.. onwards… Selection Stuff