Delete when disconnected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
When implementing an MPxNode, there's an option to setExistWithoutInConnections(false); such that the node is deleted automatically whenever a connection to it is broken. That's great!
Is there a similar option for creating nodes in Maya, either via the API or cmds?
Psuedo-code:
from maya import cmds
parent = cmds.createNode("transform")
cube, _ = cmds.polyCube()
cmds.connectAttr(parent + ".translateX", cube + ".translateX")
# Delete `cube` when `parent` is deleted
cmds.setExistWithoutInConnections(cube, False)
The specific problem I'm facing is when I build a network of nodes, one of which is a user-interactable node, like a transform with visual handle. The user could then delete this transform node, but alas! It leaves behind the additional DG nodes created to keep it company, like `multiplyDivide` and `composeMatrix` nodes. I'd like these associated to this transform, such that they are removed as soon as the transform no longer plugs into it.
Worst case, I'll have to install event handlers onto my node to monitor disconnects, but would rather not given that I'd like this behavior to persist on scene save and can already see the hoops I'd need to jump through to make that work.