PDA

View Full Version : Strange issue with MPxNode::initialize()!Help!


Windows90
12-05-2010, 07:03 AM
Hi,
I get a really strange problem when deal with custom node's initialize() method!
Here's my code:


//#define _test(_stat,_str) if(!(_stat)){MGlobal::displayError(MString("")+_str);return _stat;}
// Create attrs
aInColor1R =nAttr.create("color1R","c1r",MFnNumericData::kFloat,0);
aInColor1G =nAttr.create("color1G","c1g",MFnNumericData::kFloat,0);
aInColor1B =nAttr.create("color1B","c1b",MFnNumericData::kFloat,0);
aInColor1 = nAttr.create("color1","c1",aInColor1R,aInColor1G,aInColor1B,&stat);
_test(stat,stat.errorString());
nAttr.setKeyable(true);

// Add attrs
stat = addAttribute( aInColor1R ); _test(stat,"Add attribute color1R failed.");
stat = addAttribute( aInColor1G ); _test(stat,"Add attribute color1G failed.");
stat = addAttribute( aInColor1B ); _test(stat,"Add attribute color1B failed.");
stat = addAttribute( aInColor1 ); _test(stat,"Add attribute color1 failed.");



As you see it's just a simple shading node's input color attribute.
When I compiled and try to load it into maya, Maya displays err say "Add attribute color1R failed.", and I checked the errString, it says "(kInvalidParameter): Object already exists"

I have no idea what maya is talking about. But when I try following code:

aInColor1R =nAttr.create("color1R","c1r",MFnNumericData::kFloat,0);
stat = addAttribute( aInColor1R ); _test(stat,"Add attribute color1R failed.");

aInColor1G =nAttr.create("color1G","c1g",MFnNumericData::kFloat,0);
stat = addAttribute( aInColor1G ); _test(stat,"Add attribute color1G failed.");

aInColor1B =nAttr.create("color1B","c1b",MFnNumericData::kFloat,0);
stat = addAttribute( aInColor1B ); _test(stat,"Add attribute color1B failed.");

aInColor1 = nAttr.create("color1","c1",aInColor1R,aInColor1G,aInColor1B,&stat);
_test(stat,stat.errorString());
nAttr.setKeyable(true);
stat = addAttribute( aInColor1 ); _test(stat,"Add attribute color1 failed.");


it worked, without any err. I get confused even more :surprised

So why did this happen? I use VS2005 and Maya2010, having no such problem before. Anyone had the same issue? Thanks!

uiron
12-06-2010, 07:52 AM
when dealing with compound attributes, you don't need to add child attributes to node directly. only add the top level ones, in your case - only "aInColor1".

Windows90
12-08-2010, 02:53 PM
when dealing with compound attributes, you don't need to add child attributes to node directly. only add the top level ones, in your case - only "aInColor1".

Sorry for my late reply, You are right Uiron, I remove the child adding and it initialized successfully! Thank you !

CGTalk Moderation
12-08-2010, 02:53 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.