MPlug.getValue equivalent in Python

330 views
Skip to first unread message

scroll-lock

unread,
Apr 10, 2009, 5:45:48 AM4/10/09
to python_inside_maya
I didn't find similar posts to this so I`m making a new one.
I am trying to get the value of an attribute of a node, inside the
same node.
In C++ It's done with referencing the node first, then the plug of the
node I'm interested in, and then using the myPlug.getValue function...
this function is not available in Python and the Maya Help says this:

"This method is not available from Python. See asMObject method
instead."

so I`m simply doing this:

node = OpenMayaMPx.MPxNode.thisMObject(self)
myPlug = OpenMaya.MPlug(node, myAttribute)
test = myPlug.asMObject()
print test

and I get this error inside Maya:
RuntimeError: (kFailure): Object does not exist

It's like the plug I`m using is not existing.... I can't get it to
work. Any tips ? How are you guys getting the values of a plug in
Python ?
Thanks!

scroll-lock

unread,
Apr 10, 2009, 9:10:22 AM4/10/09
to python_inside_maya
I managed to get the value like this:

node = self.thisMObject()
fnThisNode = OpenMaya.MFnDependencyNode(node)
attr = fnThisNode.attribute("testAttr")
plug = OpenMaya.MPlug(node, transp)
value = plug.asFloat()
print value

But I really want to know why the other method I know works in C++
doesn't work for me here. And am I doing it right when I'm using the
name of the attribute (as string) to get it's value ?

Chad Dombrova

unread,
Apr 10, 2009, 11:42:30 AM4/10/09
to python_in...@googlegroups.com
for an example of an api function that gets almost any type of plug
value check out pymel.core.datatypes.getPlugValue. it's good reference.

-chad

scroll-lock

unread,
Apr 13, 2009, 9:01:28 AM4/13/09
to python_inside_maya
Thanks for the reply Chad! That single function from pymel saved me 20
lines of code :)

ynedelin

unread,
May 20, 2014, 9:43:50 PM5/20/14
to python_in...@googlegroups.com
Is there a way to do this for a particular frame or even better for list of frames?

something like getAttr time flag?

Yury
Reply all
Reply to author
Forward
0 new messages