jbrigs
Hello,

My biggest weakness with maya api so far has been working with and connecting compound Array Attributes.

I currently have a simple node that takes an input weightList built after the weightListNode devkit example. Then apply the weights To a  weightList based on a correspondence table.(I am copying weights from a cluster to another object with more control points)

I got this to work, but ran into a update issue.  Like a weightedDeformer my input and output weighList are arrays.  So I can attach more than one cluster to the node.

(example:  driverCluster1.weightList[0] -> myNode.inWeightList[0] myNode.outWeightList[0] -> drivenCluster1.weightList[0] then driverCluster2.weightList[0] -> myNode.inWeightList[1] myNode.outWeightList[1] -> drivenCluster2.weightList[0])

It seems to only update when the last inputCluster in the array is transformed, in this case driverCluster2.  The weight only gets transferred for driverCluster1 when either I move driverCluster2 or If I modify the weights for driverCluster1.


Any Ideas what I might be doing wrong?
Here are the guts to my compute function(ignore the for loop seems to be an issue with using <  symbol in code mode):

if ( plug == aWeightsList or (plug.isChild() and plug.parent() == aWeightsList))
{
MObject thisNode = thisMObject();
MPlug wPlug(thisNode, aWeights);
unsigned i, j, k;
// Read from aInWeightList
MArrayDataHandle arrayHandle = block.inputArrayValue(aInWeightsList, &amp;status);
McheckErr(status, "arrayHandle construction for aWeightsList failed\n");
MArrayDataHandle outArrayHandle = block.outputArrayValue(aWeightsList, &amp;status);
McheckErr(status, "outArrayHandle construction for aWeightsList failed\n");
int count = arrayHandle.elementCount();
MArrayDataBuilder wghtListBuilder = outArrayHandle.builder();
McheckErr(status, "multiCurve::compute creating builder");
for( i = 0; i < count; i++)
{
arrayHandle.jumpToArrayElement(i);
MDataHandle eHandle = arrayHandle.inputValue(&amp;status).child(aInWeights);
McheckErr(status, "handle evaluation failed\n");
MArrayDataHandle eArrayHandle(eHandle, &amp;status);
McheckErr(status, "arrayHandle construction for aInWeights failed\n");
unsigned eCount = eArrayHandle.elementCount();
status = wPlug.selectAncestorLogicalIndex( i, aWeightsList );
MDataHandle wHandle = wPlug.constructHandle(block);
MArrayDataHandle wArrayHandle(wHandle, &amp;status);
McheckErr(status, "wArrayHandle construction failed\n");
MArrayDataBuilder wArrayBuilder = wArrayHandle.builder(&amp;status);
McheckErr(status, "wArrayBuilder accessing/construction failed\n");
for( j = 0; j < eCount; j++)
{
eArrayHandle.jumpToArrayElement(j);
float weight = eArrayHandle.inputValue(&amp;status).asFloat();
McheckErr(status, "weight evaluation error\n");
//#########################################
//Replaced correspondence table with simple setting of outWeights as if there is a one to one correspondence
MDataHandle wghtHandle= wArrayBuilder.addElement(j);
wghtHandle.set(weight);
}
status = wArrayHandle.set(wArrayBuilder);
McheckErr(status, "set arrayBuilder failed\n");
wPlug.setValue(wHandle);
wPlug.destructHandle(wHandle);
}
}else {
return MS::kUnknownParameter;
}

jbrigs
I have found a solution by creating another attribute on my plugin node that gets pulled into the compute function.  I am sure there is a better way to get the update.  But works for now.
Reply 0 0
pshipkov
How you declare the weightList attributes ?
Reply 0 0
jbrigs
This is how I initialize them:

aInWeights = numAtt.create("inWeights", "iw", MFnNumericData::kFloat, -1000.0, &status); 
numAtt.setKeyable(true);
numAtt.setArray(true);
numAtt.setReadable(true);
numAtt.setUsesArrayDataBuilder(true);
aInWeightsList = cmpAttr.create("inWeightsList", "iwl", &status);
cmpAttr.setArray(true);
cmpAttr.addChild(aInWeights);
cmpAttr.setReadable(true);
cmpAttr.setUsesArrayDataBuilder(true);
addAttribute(aInWeightsList);
aWeights = numAtt.create("weights", "w", MFnNumericData::kFloat, -1000.0, &status);
numAtt.setKeyable(true);
numAtt.setArray(true);
numAtt.setReadable(true);
numAtt.setUsesArrayDataBuilder(true);
aWeightsList = cmpAttr.create("weightsList", "wl", &status);
cmpAttr.setArray(true);
cmpAttr.addChild(aWeights);
cmpAttr.setReadable(true);
cmpAttr.setUsesArrayDataBuilder(true);
addAttribute(aWeightsList);
attributeAffects(aInWeights, aWeightsList);
attributeAffects(aInWeightsList, aWeightsList);
attributeAffects(aInWeights, aWeights);
attributeAffects(aInWeightsList, aWeights);


Reply 0 0
pshipkov
Everything looks good. Not sure why you are getting this strange behavior.
Reply 0 0
jbrigs
Thanks for taking a look Peter. 

I got it to work by wiring in the matrix from the cluster. It updates properly now.

Reply 0 0
Reply