How to remove an MNodeMessage

529 views
Skip to first unread message

Michael Boon

unread,
Dec 15, 2015, 10:25:26 PM12/15/15
to Python Programming for Autodesk Maya
Hi all,

If I add a callback to a node like this:
import maya.api.OpenMaya as om
mayaCallbackID = om.MNodeMessage.addAttributeChangedCallback(mObj, myFunc)

and then later I do
om.MMessage.removeCallback(mayaCallbackID)

I get the error
#RuntimeError: (kInvalidParameter): No element at given index

If I look at the callbacks on the node like this:
print om.MMessage.nodeCallbacks(mObj)

I can see that mayaCallbackID is among the IDs on the node.
I see examples of MNodeMessage being removed like this in the API examples, eg 

but it doesn't seem to work in Python. Has anyone done this successfully? What am I doing wrong?

Thanks,

Boon

Balazs Pataki

unread,
Dec 18, 2015, 1:24:31 PM12/18/15
to Python Programming for Autodesk Maya
Hey Michael,

I still use the 1.0 Python API in Maya 2014 (maya.OpenMaya and not maya.api.OpenMaya since it's very limited doesn\'t have MNodeMessage etc) and it works perfectly.
You should check it out with it.

Michael Boon

unread,
Jan 18, 2016, 12:35:23 AM1/18/16
to Python Programming for Autodesk Maya
Thanks, that seems to work.

(I'm not going to mark this as answered just yet...I'm hoping for a direct answer about the Python API 2.0 version of the functions)

For future ref, here's some sample working code using the old Python API
# Get the currently selected DAG object (assuming there's exactly one).
sel
= old_om.MSelectionList()
old_om
.MGlobal.getActiveSelectionList(sel)
dagPath
= old_om.MDagPath()
mObj
= old_om.MObject()
sel
.getDagPath(0, dagPath)
mObj
= dagPath.node()
print 'Object is:', dagPath.fullPathName()
# Put a callback on it.
mayaCallbackID
= old_om.MNodeMessage.addAttributeChangedCallback(mObj, myFunc)
# Delete the callback. It appears to work as expected.
old_om
.MMessage.removeCallback(mayaCallbackID)

Michael Boon

unread,
Jan 18, 2016, 4:58:51 PM1/18/16
to Python Programming for Autodesk Maya
I just tried it using API 2.0 in Maya 2016 and it works fine.

So I guess the answer is, in Maya 2015 and before, use the old API. In 2016, the new API works.
Reply all
Reply to author
Forward
0 new messages