Error with rendering attribute pixelCenter (Object already exists)

Error with rendering attribute pixelCenter (Object already exists)

morinnicolas8944
Advocate Advocate
892 Views
3 Replies
Message 1 of 4

Error with rendering attribute pixelCenter (Object already exists)

morinnicolas8944
Advocate
Advocate

I need to get the current position in the image when rendering my material node in MPxNode::compute in order to export the rendering results to an image file.

 

I plan to use the rendering attribute pixelCenter, defined in Maya Developer Help - Appendix B.

http://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=__files_Appendices_Appendix_C_Rendering_attribut...

 

I add the attribute to my node, as I do with other rendering attributes, in the node's initialize() with the following code.

 

aPixelCenterX = nAttr.create("pixelCenterX", "pcx", MFnNumericData::kFloat, 0, &status);
CHECK_MSTATUS(status);
CHECK_MSTATUS(nAttr.setStorable(true));
CHECK_MSTATUS(nAttr.setKeyable(true));
CHECK_MSTATUS(nAttr.setDefault(0.0f));

aPixelCenterY = nAttr.create("pixelCenterY", "pcy", MFnNumericData::kFloat, 0, &status);
CHECK_MSTATUS(status);
CHECK_MSTATUS(nAttr.setStorable(true));
CHECK_MSTATUS(nAttr.setKeyable(true));
CHECK_MSTATUS(nAttr.setDefault(0.0f));

aPixelCenter = nAttr.create("pixelCenter", "pc", aPixelCenterX, aPixelCenterY);
CHECK_MSTATUS(nAttr.setStorable(true));
CHECK_MSTATUS(nAttr.setKeyable(true));
CHECK_MSTATUS(nAttr.setDefault(0.0f, 0.0f));
CHECK_MSTATUS(nAttr.setHidden(true));
CHECK_MSTATUS(addAttribute(aPixelCenter));

But the last line fails with error ": (kInvalidParameter): Object already exists".

 

It appears to work if I change the brief names of the attributes to ones that are different from the ones specified in Appendix B.

 

I observed the problem with Maya 2017 Update 2. I did not try yet with other versions of Maya.

0 Likes
Accepted solutions (1)
893 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Accepted solution

Do you maybe add another attribute to your node, which is using the short name "pc" already?

0 Likes
Message 3 of 4

morinnicolas8944
Advocate
Advocate

@Anonymous wrote:

Do you maybe add another attribute to your node, which is using the short name "pc" already?


You're right, I only checked my custom attributes so I didn't notice it, but I was also using "pc" for pointCamera!

Setting the short name for pointCamera to "p" fixed the problem.

 

Now I feel silly Smiley Embarassed

 

Thanks for your help!

0 Likes
Message 4 of 4

Anonymous
Not applicable

Happen to all of us from time to time 🙂

0 Likes