Here's one example:
My custom node is called clothWrinkle. This node takes input from a nurbs curve and a triangular mesh. If the connection is broken between the curve and the node, then I need to delete this node.
Right now, I'm using an aboutToDelete callback to watch the curve node for deletion (I set it up in connectionMade). In the callback, I use the modifier to disconnect the curve from the node (as it seems the connection is still there on the node's side) and disconnect the mesh from the curve (mod.disconnect). I set setExistWithoutInConnections(false) so the node is then set to be deleted.
I have a second custom node that takes as input the triangular mesh, as well as multiple clothWrinkle nodes and produces a resulting mesh. When all the clothWrinkle nodes are deleted then this node needs to be deleted. I do the same thing in the callback (disconnect connections), and I also add the triangular mesh to its original shading group. In this callback, I also delete the parent transform node.
So, all the operations I use are mod.disconnect except for 1 mod.deleteNode and 1 of each of "sets -rm" and "sets -add".
Node 1 (clothWrinkle):
input -> curve, mesh
output -> mesh
Node 2
input -> mesh, multiple clothWrinkle nodes
output -> mesh
It looks like maybe the modifier queue holds multiples for the set operations since when the callback is called after an undo, I get errors saying the polySurfaceShape (output of node 2 that is connected to the shading group) does not exist.
thanks for any help
CODE
void ClothWrinkleNode::aboutToDeleteCB( MObject &node, MDGModifier &mod, void* clientData )
{
MStatus stat;
MFnDependencyNode nodeFn;
MPlug plug;
MPlugArray plugs;
nodeFn.setObject( node );
MString plugName = nodeFn.findPlug( "worldSpace" ).name();
if( node.apiType() == MFn::kNurbsCurve )
{
MObject obj;
// Find clothWrinkle node without input curve connection
MSelectionList selection;
MGlobal::executeCommand( "select -r ls -type \"clothWrinkle\"
" );
MGlobal::getActiveSelectionList( selection );
for( int i = 0; i < (int) selection.length(); i++ )
{
selection.getDependNode( i, obj );
nodeFn.setObject( obj );
plug = nodeFn.findPlug( "inCurve" );
plug.connectedTo( plugs, true, false );
break;
}
}
// inCurve connection (if not already disconnected)
plug = nodeFn.findPlug( "inCurve" );
plug.connectedTo( plugs, true, false );
if( plugs.length() > 0 )
mod.disconnect( plugs[0], plug );
// inMesh connection
plug = nodeFn.findPlug( "inMesh" );
plug.connectedTo( plugs, true, false );
if( plugs.length() > 0 )
mod.disconnect( plugs[0], plug );
}