[MPlug] error on get attribute

263 views
Skip to first unread message

Rémi Deletrain

unread,
Jun 22, 2018, 5:17:56 AM6/22/18
to Python Programming for Autodesk Maya
I everyone,

I found an error on get attribute "rotatePivot" with api.

It's possible to get this attribute with MFnDependencyNode like this

m_sl = OpenMaya.MSelectionList()
m_sl.add("null1")

mo = OpenMaya.MObject()
m_sl.getDependNode(0, mo)

mfn = OpenMaya.MFnDependencyNode(mo)
mp = mfn.findPlug("rotatePivot")

But is not possible to get this attribute with MSelectionList

m_sl = OpenMaya.MSelectionList()
m_sl.add("null1.rotatePivot")

mp = OpenMaya.MPlug()
m_sl.getPlug(0, mp)

But it's possible to get children like this

m_sl = OpenMaya.MSelectionList()
m_sl.add("null1.rotatePivotX")

mp = OpenMaya.MPlug()
m_sl.getPlug(0, mp)

It's normal ?

Cedric Bazillou

unread,
Jun 23, 2018, 3:53:52 PM6/23/18
to Python Programming for Autodesk Maya
Depends on what your trying to achieve.
selection list first usage is for dag/dependency node and components.

Once you access them you can access their attributes easily 
So at first read what you point out doesn't look like an error.

Rémi Deletrain

unread,
Jun 28, 2018, 12:05:19 PM6/28/18
to Python Programming for Autodesk Maya
I want to get a vector attribute like translate.
Attribute translate and rotatePivot is a same type. But get rotatePivot doesn't work and get translate works fine.

from maya import OpenMaya

def get_mplug(s_attr_node):
    m_sl = OpenMaya.MSelectionList ()
    m_sl.add (s_attr_node)
    mp = OpenMaya.MPlug ()
    m_sl.getPlug (0, mp)
    return mp

try:
    mp_translate = get_mplug("joint1.translate")
    print mp_translate.child(0).name()
    print mp_translate.child(1).name()
    print mp_translate.child(2).name()
except:
    print "Get translate doesn't works"
else:
    print "Get translate works"

try:
    mp_rotate_pivot = get_mplug("joint1.rotatePivot")
    print mp_rotate_pivot.child(0).name()
    print mp_rotate_pivot.child(1).name()
    print mp_rotate_pivot.child(2).name()
except:
    print "Get rotatePivot doesn't works"
else:
    print "Get rotatePivot works"


Cedric Bazillou

unread,
Jun 29, 2018, 4:35:13 AM6/29/18
to Python Programming for Autodesk Maya
oh i know pretty much every part of the api related to animation / rigging.
Im just pointing out that in order to use the API in python you have to follow some strict procedure ( automatic binding with swig)

import maya.OpenMaya as OpenMaya
def getMObject(nodeName):
    selList = OpenMaya.MSelectionList()
    OpenMaya.MGlobal.getSelectionListByName(nodeName,  selList)
    depNode = OpenMaya.MObject()
    selList.getDependNode(0, depNode) 

    return depNode
    

nodeFn = OpenMaya.MFnDependencyNode(getMObject('joint1'))
matrixPlug = nodeFn.findPlug('rotatePivot')

for childIndex in range(matrixPlug.numChildren()):
    print matrixPlug.child(childIndex).asFloat()


Hence me getting a plug from dependency Mfn function set and not fiddling with the MSelectionList ( which conceptually is for dag/dependency and components).
Most of the time when working with python programmer, or other artist i have to point out that the api is exposed and use some python syntax but you must adopt maya philosophy ( so asking for more pythonic doesnt make sense  : at some point
you will write it in c++ and your python code will be a waste of time to translate back to pure API)
Message has been deleted

Rémi Deletrain

unread,
Jul 4, 2018, 3:47:49 AM7/4/18
to Python Programming for Autodesk Maya
Thank you for your answer Cédric.

I understand the usefulness of thinking in cpp and not in python. I try to do it as much as possible and I optimize a lot of code thanks to that.
Sometimes I use "shortcuts" to go a little faster in prototyping, like the getPlug function of the MSelectionList.
I also do according to what I am given, here a json with string and thus the function getPlug when I have "myNode.myAttribute" to go "fast" in code. But it forces either to cut the string or to rethink the file generation logic that is not based on the Maya API. Eventually it will come but for the moment we are in phase of test and transformation of some script.

Only the fact that getPlug works with the attribute "translate" and not "rotatePivot" calls me. For me, they are attributes of the same type.
But as the recovery does not work there is necessarily a difference and I want to know which one.
Reply all
Reply to author
Forward
0 new messages