Scanning through MEventMessage, there doesn’t seem to be an event linked to deleting a DAG object. There is one for DagObjectCreated, and an event for deleteAll, but nothing that will trigger off plain old delete…
To give some context, I am trying to update a GUI when objects are added/removed from the scene.
Update: It seems what I need is under MConditionMessage, not MEventMessage!
You can do it in commands with an attributeDeleted scriptJob. You probably want to make it a runOnce so it doesn’t hang around after the object is deleted. FWIW that will also survive name changes, so you can set it up on an object, rename the object in script, and still get the notiifcation
i need something that will trigger off the deletion of any object. I think the MConditionEvent will suit my needs for the time being, but I will keep that in mind.
as an exercise, I am creating my own tree view that mimics maya’s outliner using the principles set out in Rob’s book, divorcing the maya code from the GUI and wiring them together with signals. I want my UI to respond to NewName, DagObjectCreated and delete events so it will stay up to date when not in focus.
def func(*args):
print "Event triggered!"
print args
myNode = pm.selected()[0]
mObj = myNode.__apimobject__()
myEventID = om.MNodeMessage.addNodePreRemovalCallback(mObj, func)
# delete the object to trigger the event
om.MMessage.removeCallback(myEventID) # always clean your events up!
I did eventually end up using MNodeMessage.addNodePreRemovalCallback
Thanks!