View Full Version : Api: AddAttr like cmd?
04 April 2006, 03:50 PM
I am hunting around for a way to add attributes to already created nodes.
Say for example I use the MFnNurbsCurve::createCurve() to make a curve, in the dag there exist a nurbscurve node. How does one go about adding attributes to that node?
I do not want to make a new node like the examples mentioned, I simply want to do like what the addAttr mel command does only in the api.
Offcourse there is the MGlobal::executeCommand, but I decided to ask here before taking that route.
Thanks in advance.
04 April 2006, 04:05 PM
I dont know how to help on that dude. I am starting to learn to write Maya API. Though, if you dont get any answer here, go to highend3D forum in the Maya API section, they should help you there!!!
04 April 2006, 04:57 PM
use the MFnAttribute derived classes (e.g. MFnNumericAttribute) to create the attribute. Then use the MFnDependencyNode (the base class of all node function sets) to add the attribute via addAttribute()
It should be fairly straightforward, array attributes, matrices etc are a bit more involved....
04 April 2006, 05:01 PM
Robert. You're the man dude..
04 April 2006, 06:58 PM
Thanks for the quick feedback,
I am having this really strange quirk when I am creating the curves.
I am able to create the curves when I execute the command, but I cannot get access to the cunrve functions. Hence the reasone why the addAttribute as Rob mentioned isnt working for me.
Here is the code I am using;
MObject curveObj = curveFn.create( points, knots, 3,
MObject::kNullObj, &stat );
melCmd += MString("-> ") + curveFn.fullPathName() + "\n";
MGlobal::displayInfo( melCmd );
so when I run the plugin, it creates the curves, but it doesnt give me the path name of the curve.... I seriously dont know what I am doing wrong....
ok one solution is that when you are creating many curves under one loop you would need to make a transform object and use that in the createCurve function ....
I hope it helps those who are having the same issue...
oh and just to add the addAttribute works fine.. and thanks for the replies guys once again
04 April 2006, 06:04 PM
this is a side-effect that applies to any dag node created in maya (light,mesh, locator etc). Basically it always creates one of those shapes parented to a transform (ie, it's also created a transform).
The MObject returned in those cases is the transform node. the function set becomes invalid because maya has attempted to attach it to a transform. Basically attach an MFnDagNode to the returned object, and then re-initialise the function set with the transforms first child. A pain i know....
04 April 2006, 06:04 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.