Thanks for confirming, Pedro!

On Tue, 28 Aug 2018 at 04:59, Pedro Bellini <[email protected]> wrote:

> Hey,
> First there is nothing wrong with the way you got it to work.
> Second, have you tried getting the plug straight from MSelectionList() ?
> it could work for you...
>
> ie.
>
> Yeah, maybe it works. If not, your way is fine too.
> from maya.api import OpenMaya
> from maya import cmds
>
> pma = cmds.createNode('plusMinusAverage')
> plug = OpenMaya.MSelectionList().add(pma+'.input3D[1].input3Dx').getPlug(0)
>
> plug.name()
> # Result: u'plusMinusAverage1.input3D[1].input3Dx' #
> plug.asFloat()
> # Result: 0.0 #
>
> plug2 = OpenMaya.MSelectionList().add('persp.t').getPlug(0)
>
> pcst = cmds.createNode('parentConstraint')
> plug3 =
> OpenMaya.MSelectionList().add(pcst+'.target[0].targetOffsetTranslate').getPlug(0)
> plug3.name()
> # Result: u'parentConstraint1.target[0].targetOffsetTranslate' #
> plug3.isCompound
> # Result: True #
>
> plug3b =
> OpenMaya.MSelectionList().add(pcst+'.target[0].targetOffsetTranslateX').getPlug(0)
> plug3b.asFloat()
> # Result: 0.0 #
>
> # for some reason this does not work in a few of attributes (not sure why)
> # rotatePivot
> plugFail = OpenMaya.MSelectionList().add('persp.rotatePivot').getPlug(0)
> # TypeError: item is not a plug #
> cmds.objExists('persp.rotatePivot')
> # Result: True #
>
> # which makes me get it the other way you mentioned
> fnDg =
> OpenMaya.MFnDependencyNode(OpenMaya.MSelectionList().add('persp').getDependNode(0))
> plugRp = fnDg.findPlug('rotatePivot', False)
> plugRp.isCompound
> # Result: True #
> plugRp.numChildren()
> # Result: 3 #
>
>
> Cheers.
>
>
> On Monday, August 27, 2018 at 7:22:31 AM UTC-7, Marcus Ottosson wrote:
>>
>> Hi all,
>>
>> I’m looking for how to query a compound plug within an array plug, by
>> name.
>>
>> With non-compound attributes, you can query plugs using the function set.
>>
>> from maya.api import OpenMaya as om
>> node = fn.create("wtAddMatrix")
>> fn = om.MFnDependencyNode()
>> nodeState = fn.findPlug("nodeState", False)
>>
>> Likewise, I can get to the compound plug and its first index like this..
>>
>> mplug = fn.findPlug("wtMatrix", False)assert mplug.name().rsplit(".", 1)[-1] 
>> == "wtMatrix"assert mplug.isArray and mplug.isCompound
>> first = mplug.elementByLogicalIndex(0)assert first.name().rsplit(".", 1)[-1] 
>> == "wtMatrix[0]"
>>
>> And I can guess my way to the weightIn attribute, by grabbing it by an
>> arbitrary index.
>>
>> # wtAddMatrix#   [0]#      .matrixIn#      .weightIn#   [1]#      .matrixIn# 
>>      .weightIn#    ..
>> weigthIn = first.child(1)assert weigthIn.name().rsplit(".", 1)[-1] == 
>> "weightIn"
>>
>> But how can I get to nested the wtAddMatrix.wtMatrix[0].weightIn
>> attribute by name?
>>
>> weightIn = ... # By name?
>>
>> Seeing as it’s the function set of a node that enables findPlug(), I
>> can’t figure out how to apply this to the MPlug itself.
>>
>> For the moment, I’ve “hacked” it by iterating through children till I
>> find a match.
>>
>> for index in range(first.numChildren()):
>>   child = first.child(index)
>>   if child.name().rsplit(".", 1)[-1] == "weightIn":
>>     return child
>>
>> But it doesn’t look right.
>>
>> Any ideas?
>>
>> Best,
>> Marcus
>>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/81d19ff3-3192-4b9f-8bce-e991f1ab9a79%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/81d19ff3-3192-4b9f-8bce-e991f1ab9a79%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODD27u8MfeJUd-809vZXzVxOfezRB8N1hZ7%2BfSfiatKww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to