I am writing a deformer node which takes as inputs the worldMatrix and visibility of cylinders. The cylinders are organised into groups, and this structure is mirrored on my deformer. I have a 2D array, organised by groups with cylinders for children, and each array is a compound attribute, so I can control an entire groups visibility and individual holes.
This is the attribute setup:
aVisibility = nAttr.create("Visibility", "vis", MFnNumericData::kBoolean);
CHECK_MSTATUS(addAttribute(aVisibility));
aTransform = mAttr.create("Transform", "trans", MFnMatrixAttribute::kDouble);
nAttr.setDisconnectBehavior(MFnAttribute::DisconnectBehavior::kDelete);
CHECK_MSTATUS(addAttribute(aTransform));
aCylinders = cAttr.create("Cylinders", "cylinders");
cAttr.addChild(aTransform);
cAttr.addChild(aVisibility);
cAttr.setArray(true);
CHECK_MSTATUS(addAttribute(aCylinders));
aGroupVisibility = nAttr.create("GroupVisibility", "grpVis", MFnNumericData::kBoolean, true);
nAttr.setDisconnectBehavior(MFnAttribute::DisconnectBehavior::kDelete);
CHECK_MSTATUS(addAttribute(aGroupVisibility));
aGroups = cAttr.create("Groups", "grps");
cAttr.addChild(aGroupVisibility);
cAttr.addChild(aGroupHoles);
cAttr.setArray(true);
CHECK_MSTATUS(addAttribute(aGroups));
I have written python scripts to add a cylinder to this, which will figure out which group it should belong to, add a new entry and connect the visibility and worldMatrix up.
I have a couple of problems with this setup. First, deleting a cylinder acts as I would expect since I have defined disconnectBehaviour to delete the instance in the array. However deleting a group leaves a disconnected attribute at the top level of the hierarchy which I have to clean up manually.
Second, while deleting works quite well, it would be really handy if duplication could be used as well. So if somebody duplicated a cylinder, an array entry was created and the necessary attributes connected. Is this possible? So far people using the deformer have naturally attempted this, and I have had to make them use a script.