- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I'd like to track when a node is accessible to the user, but am having trouble finding the means of tracking when a node is *removed* from the scene. The holdout is when the node is removed from undo, such as creating and then immediately undoing the creation.
- MNodeMessage::addNodePreRemovalCallback This covers all removal I need, except removal via undo
- MDGMessage::addNodeAddedCallback This covers all addition I need, incl. via undo
from maya import cmds
from maya.api import OpenMaya as om
cmds.loadPlugin("destroyMePlease")
mod = om.MDagModifier()
parent = mod.createNode("transform")
rigid = mod.createNode("destroyMePlease", parent=parent)
mod.doIt()
mod.undoIt()
# Callback not called
# ~destructor not called
cmds.file(new=True, force=True)
# still not called
cmds.unloadPlugin("destroyMePlease")
# RuntimeError: Plug-in, "destroyMePlease", cannot be unloaded because it is still in use #
del mod
# ~destructor called
# But not callback
cmds.unloadPlugin("destroyMePlease")
# Success!
I've got a reproducible here for the finer details.
- https://gist.github.com/mottosso/939ecaa992a3c98df5988484bbfb5e02
The secondary issue is not being able to unload a plug-in until the destructor is called, which won't happen until the MDagModifier is destroyed from Python. Any workaround for that would also be great :S Python should *not* be allowed to keep nodes around, references should be weak.
Applies to Maya 2018-2020.2. Any ideas?
Solved! Go to Solution.