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.

On Monday, 18 January 2016 16:35:23 UTC+11, Michael Boon wrote:
>
> 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)
>
>
> On Saturday, 19 December 2015 05:24:31 UTC+11, Balazs Pataki wrote:
>>
>> 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.
>>
>> On Wednesday, December 16, 2015 at 4:25:26 AM UTC+1, Michael Boon wrote:
>>>
>>> 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 
>>>
>>> http://help.autodesk.com/view/MAYAUL/2015/ENU/?guid=__cpp_ref_hw_unlit_shader_2_node_monitor_8cpp_example_html
>>>
>>> but it doesn't seem to work in Python. Has anyone done this 
>>> successfully? What am I doing wrong?
>>>
>>> Thanks,
>>>
>>> Boon
>>>
>>

-- 
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/f8188d76-356a-463b-9eb7-83406dd0402f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to