Concept:
To start I would like to explain what I'm trying to accomplish here. I am creating a series of custom nodes that I will connect together.
The first node in the chain is an "inluence" node. This influence node connects into an "influenceNetwork" node that creates a
doubleArray of normalized weights for each influence node based on each one's proximity to a connected input mesh. These weights
arrays are then plugged into my main node to drive different attributes across the surface.
Attribute Creation Code
// main node attributes
//
MFnCompoundAttribute cAttr;
flow_curves_attr = cAttr.create("flowCurves", "fwc");
flow_curve_weights_attr = tAttr.create("flowCurveWeights", "fwcw", MFnDoubleArrayData::kDoubleArray);
CHECK_MSTATUS(cAttr.addChild(flow_curve_weights_attr));
flow_curve_matrix_attr = mAttr.create("flowCurveMatrix", "fwcm");
CHECK_MSTATUS(cAttr.addChild(flow_curve_matrix_attr));
CHECK_MSTATUS(cAttr.setArray(true));
CHECK_MSTATUS(addAttribute(flow_curves_attr));
// influenceNetwork node attributes
//
normalized_weights_double_array_attr = tAttr.create("normalizedWeightsDoubleArray", "nwda", MFnDoubleArrayData::kDoubleArray);
CHECK_MSTATUS(tAttr.setKeyable(false));
CHECK_MSTATUS(tAttr.setStorable(false));
CHECK_MSTATUS(tAttr.setReadable(true));
CHECK_MSTATUS(tAttr.setWritable(false));
CHECK_MSTATUS(tAttr.setArray(true));
CHECK_MSTATUS(tAttr.setUsesArrayDataBuilder(true));
CHECK_MSTATUS(addAttribute(normalized_weights_double_array_attr));
MFnCompoundAttribute cAttr;
elements_attr = cAttr.create("elements", "e");
element_strength_attr = nAttr.create("elementStrength", "es", MFnNumericData::kDouble, 1.0);
CHECK_MSTATUS(cAttr.addChild(element_strength_attr));
element_matrix_attr = mAttr.create("elementMatrix", "em");
CHECK_MSTATUS(cAttr.addChild(element_matrix_attr));
CHECK_MSTATUS(cAttr.setArray(true));
CHECK_MSTATUS(addAttribute(elements_attr));
CHECK_MSTATUS(attributeAffects(elements_attr, normalized_weights_double_array_attr));
CHECK_MSTATUS(attributeAffects(element_strength_attr, normalized_weights_double_array_attr));
CHECK_MSTATUS(attributeAffects(element_matrix_attr, normalized_weights_double_array_attr));
Connections:
influence.strength -> influenceNetwork.elements[n].elementStrength
influence.worldMatrix[0] -> influenceNetwork.elements[n].elementMatrix
influence.worldMatrix[0] -> mainNode.flowCurves[n].flowCurveMatrix
influenceNetwork.normalizedWeightsDoubleArray[n] -> mainNode.flowCurves[n].flowCurveWeights
Problem:
I would like to have it where when an influence node is deleted, both the influenceNetwork node and my main node detect that there
is no longer a connection to the matrix child attributes and remove that multi instance of the compound array. I searched for a way to
do this from within the api but all I found was the disconnectBehavior for a regular array attribute which won't work for my needs
because I am not connecting the array element itself.
The solution I came up with was when my nodes compute, I test the matrix children for connections and if it is not connected I call MGlobal::executeCommand("removeMuliInstance -break true ") on that element in the array. This worked until I connected
the output weights from the influenceNetwork into the weights child attribute of my main node. Now it gives me this when I try to
delete one of the influence nodes:
(I am printing the command that gets run from within the nodes as well as the status that gets returned from running those commands)
removeMultiInstance -break true mainNode1Shape.flowCurves[2]
removeMultiInstance -break true influenceNetwork.elements[2]
NetworkNode::command_status = No error
MainNode::command_status = (kFailure): Unexpected Internal Failure
It also prints the following to the scriptEditor:
// Error: line 1: Unable to remove mainNode1Shape.flowCurves[2]. //
Is there any way to have a node detect that a child of a compound array element is no longer connected and remove that element of the compound array?