maya.OpenMaya and negative index in MPlug::partialName

290 views
Skip to first unread message

sergei nazarenko

unread,
Feb 2, 2016, 8:59:58 AM2/2/16
to Python Programming for Autodesk Maya
Help me ))

I need to get the right name of attribute but Maya gives me wrong (((


import maya.OpenMaya as om

# add in selection
selList = om.MSelectionList()
selList.add("blendShape1")
# get MObject
selObj = om.MObject()
selList.getDependNode(0,selObj)
# attach to dependency Fn set
fnDepend = om.MFnDependencyNode(selObj)
totalAttrs = fnDepend.attributeCount()
for i in range(0,totalAttrs):
    attrObj = fnDepend.attribute(i)
    fnAttr = om.MFnAttribute(attrObj)
    if fnAttr.isStorable() and fnAttr.isWritable():
        plug = fnDepend.findPlug(attrObj)
        print plug.partialName(True, True, True, False, True, True)

....
blendShape1.inputTarget[-1].normalizationGroup[-1].normalizationUseWeights
....


I need name like "blendShape1.inputTarget[0].normalizationGroup[0].normalizationUseWeights" . It is how Connection Editor shows given attribute name.

In which way I can get the right indexes?

I would be very appreciated for any help

Sergiy,
Best


Paul Molodowitch

unread,
Feb 2, 2016, 12:50:06 PM2/2/16
to Python Programming for Autodesk Maya
That's because you're trying to get the plug from just the attribute name.  One thing that can be confusing when first starting to use OpenMaya is that the word "attribute" is used somewhat differently in the api than it is in mel / maya.cmds... and the api also introduces a new concept, a "plug".

The generally like to think of the difference like that between classes and instance in maya; an api "attribute" describes a class of attributes, and a "plug" is like a specific instance of that class.  So, for instance, the "visibility" attribute describes the qualities of that attribute across all nodes (ie, whether it is keyable, what sort of data it holds, etc), while a plug represents one specific instance of that attribute on one specific node. In fact, it gets even more granular than that - there are different plugs for inputs and outputs to that attribute (not to mention networked and non-networked plugs - but that's something I'm not going to dive into now).

In your case, you've got a specific node, and you're trying to find the plug associated with an attribute on that node... but since your attribute is the child of an array attribute (or a "multi" attribute, in mel-speak), it still doesn't have enough information to get a specific plug for that attribute.  I sort of wish the api would just error in this situation, because I think it would be clearer, but instead, it returns a sort of "placeholder" plug, that just "placeholder" indices (those "-1" indices).  Because it's not pointing at any specific plug, it's really not good for much (at least as far as I know). You need to get a specific index, for both it's parent array attributes, before you can do something useful with it.

However, you haven't made clear which one you're looking for.  Are you trying to iterate over all instances of that plug (for all indices of both parent attributes)? Do you just want a plug that actually exists, but you don't really care which one?  If so, note that it's possible that NO "real" instances of that plug exists, because one of the parent array plugs might currently have no members...

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/52c5d426-679e-4b79-bfe9-9df27544ccec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sergei nazarenko

unread,
Feb 3, 2016, 9:16:21 AM2/3/16
to Python Programming for Autodesk Maya
Thanks for explanation!

Actually I need to build the three of attributes like Connection Editor.
So, I want to pass through all attributes and get a specific indeces for parent if it is a array. 

Maybe it is not right approach to use MFnDependencyNode::attributeCount() and MFnDependencyNode::attribute(index, &stat) for loop. 
As far I understand it is impossible to get specific index of parent from child MPlug. Child has not any information about such things.
Thus, I need to iterate recursively over attributes tree. 
But it is possible with current Maya API? It is intresting how it done in Connection Editor?


sergei nazarenko

unread,
Feb 3, 2016, 9:31:07 AM2/3/16
to Python Programming for Autodesk Maya
I use c++ to build maya command and situation the same but in some cases it different

MObject dependNode;   
MItSelectionList iter( listObjects, MFn::kInvalid, &stat );
for ( ; !iter.isDone(); iter.next() ) 
    {
        stat = iter.getDependNode( dependNode ); CHK
        MFnDependencyNode fn(dependNode);

        for(int j = 0; j < totalAttrs; ++j)
        {
            MObject attrObj = fn.attribute(j, &stat); CHK
            MPlug plug = fn.findPlug(attrObj, &stat ); CHK

            std::cerr << "ATTR: " << j << " " 
                << plug.partialName(includeNodeName, useAlias, useFullAttributePath, useLongNames, &stat) ;
                << std::endl;
...
ATTR: 27 blendShape1.it[0].itg[0].iti[6000].igt
ATTR: 28 blendShape1.it[-1].itg[-1].iti[-1].ipt
....

For some attribute it's works for other it not (((

Reply all
Reply to author
Forward
0 new messages