Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

C++ adding attributes in "Extra Attributes"

1 REPLY 1
Reply
Message 1 of 2
MikeSSSS
526 Views, 1 Reply

C++ adding attributes in "Extra Attributes"

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");
	}

 

1 REPLY 1
Message 2 of 2
MikeSSSS
in reply to: MikeSSSS

Was able to 'sort of' find a solution on Maya 2020:

 

Made a static class, then was able to add a callback function.

s_callbackID = MNodeMessage::addAttributeChangedCallback(node, userCB, NULL, &stat);

 

It doesn't seem to register unless I add it twice however, which is likely going to cause problems elsewhere.

 

Anyone else have issues or solutions with this?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report