Feedback

What's your question?

By: [ Editor ] Asked from United States of America

How to make compound attributes work?

I created a block of code that creates a compound attribute array and a child array attribute. When I create the node in Maya and try to "Add new item", I get the following error:

// Error: file: C:/Program Files/Autodesk/Maya2009/scripts/AETemplates/AEnewCompound.mel line 129: Found no attribute match for "node.childAttr" //

Here's what's in my cpp file:

MFnNumericAttribute childAttrFn;
aChild = childAttrFn.create("childAttr", "ca", MFnNumericData::kFloat, 0.0);
childAttrFn.setArray(true);
childAttrFn.setStorable(true);
childAttrFn.setKeyable(true);
childAttrFn.setReadable(true);
childAttrFn.setWritable(true);
childAttrFn.setUsesArrayDataBuilder(true); 
addAttribute( aChild );

MFnCompoundAttribute cmpAttrFn;
aCmp = cmpAttrFn.create("Compound", "cmp");
cmpAttrFn.setArray(true);
cmpAttrFn.addChild( aChild );
cmpAttrFn.setReadable(true);
cmpAttrFn.setUsesArrayDataBuilder(true); 
addAttribute( aCmp );

Add comment viewed 680 times Latest activity 11 months ago

NN comments
manny
-

I was using the “weightListNode.cpp” example from Maya. I just compiled that plugin and got the same error! THANKS MAYA!!!

or Cancel

1 answer

  • 1

julian [ Admin ]

  • The "Add New Item" button in the attribute editor is a bit naive. It handles most simple attribute types as array elements, but what you have is a compound multi for each element. Try with:

    setAttr node.Compound[0].childAttr[0];

If that works, then you may need to implement an AEtemplate to handle it.

  • This may or may not be relevant, but at some point I think Autodesk changed the way you add children to a compound through the API. There's no longer any need to call MPxNode::addAttribute() on the child. When you use MFnCompoundAttribute::addChild() on the compound it takes care of adding the attribute.
NN comments
manny
-

Hi Julian, I was hoping you’d answer. But unfortunately, it still doesn’t work. I did “getAttr node.cmp[0].child[0]” and I got the same error, “found no matching attribute”.

manny
-

OK, if I just ignore the error and continue getting and setting the attribute array, it will take the values. It will error again on the next compound array index. But ignoring it works. Is there any way around the error in the first place? There must be because this is how Maya’s weightList.weights functions in their deformer node.

manny
-

Yes, I think you’re right about using my own AEtemplate. That should solve the error issue. Thanks Julian.

or Cancel