Hello,
I have figured out how to add attributes using mel with addAttr and setAttr on a particular object, but I am struggling to do so with C++.
With C++, I want to ideally add an attribute to an object dynamically when my plugin starts, and then propogate those attributes to other objects.
The pieces I am playing around with are below--I just want to know if I am on the right track as far as doing this with the C++ api.
MFnNumericAttribute attr;
MGlobal::executeCommand("select MyParentObject;");
MObject newAttr = attr.create("testAttribute", "t", MFnNumericData::kDouble, 0.0);
MDagPath node;
MObject component;
MSelectionList list;
MFnDagNode nodeFn;
MPxNode n;
n.addAttribute(newAttr);
// From our selection list
MGlobal::getActiveSelectionList(list);
for (unsigned int index = 0; index < list.length(); index++){
list.getDagPath(index, node, component);
nodeFn.setObject(node);
nodeFn.addChild(newAttr);
MStatus stat = nodeFn.addAttribute(newAttr);
if (MS::kSuccess != stat) {
MGlobal::displayInfo("Failed to add attribute");
}
MGlobal::displayInfo(nodeFn.name().asChar());
MGlobal::displayInfo(" is selected");
}