Question 1:
The MEL command “ScriptJob” will list all of the current ScriptJobs. This is handy for tracking user scriptjobs and verifying they have been removed. As far as I can tell, there is no way to get a list of currently registered callbacks from MMessage and subclasses.
Question 2:
If I assign a “MNodeMessage.addNodePreRemovalCallback” to a node and that node is deleted, is the callback automatically removed once the node is deleted? If I had another callback on that same node, say “MNodeMessage.addNameChangedCallback”, would it also be automatically removed once the node is deleted? Or do I have to manually remove these callbacks when the node is deleted?
So I’ve not found any way to query the api about active callbacks.
Instead I just manually keep track of any that I create, also I’m only using the MSceneMessages currently, I’ve not really messed with the MNodeMessage callbacks.
I’m not sure if the callback will still be triggered after deleting the node, but the callback does still exist.
You can check by saving the id number from the add callback method, and after deleting the node the MMessage.removeCallback(id) will be successful.
If you try to call it again, it will throw an exception saying ‘No element at given index’.
Thanks, I was afraid of that. I have been in habit of manually removing callbacks, but in the case of a delete callback I wasn’t sure if worked like scriptJobs that run once and then delete themselves.
It might be possible to trigger the delete command with something like maya.utils.executeDeferred inside the node deletion callback. That way you’re always cleaning up after yourself. Then again it might cause the whole thing to explode, the API is fun like that.