# Retreiving attribute values for a saved custom object on load

**URL:** https://forum.highend3d.com/t/retreiving-attribute-values-for-a-saved-custom-object-on-load/37840
**Category:** Maya
**Tags:** api
**Created:** [July 12, 2015, 9:34am UTC](https://forum.highend3d.com/t/retreiving-attribute-values-for-a-saved-custom-object-on-load/37840 "2015-07-12T09:34:28Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![fanaticlatic](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/f/b9e5f3/32.png) [@fanaticlatic](https://forum.highend3d.com/u/fanaticlatic)
#### Post date: [July 12, 2015, 9:34am UTC](https://forum.highend3d.com/t/retreiving-attribute-values-for-a-saved-custom-object-on-load/37840/1 "2015-07-12T09:34:28Z")

</div>

Hi,

I have created a custom MPxSurfaceShape to store the attributes for a camera frustrum based upon the shapes bounding box values.

It currently works perfectly for creating new nodes because the recomputeFrustrum function gets called when the frustrum attributes are dirtied.  
When loading a maya scene containing this custom node the compute function is not called, meaning recomputeFrustrum is never called. Leaving the custom node drawing the frustrum using the default vertex array rather than using the correct attribute editor values for that custom node.

so my camera is initialized among other things with:

…  
//&nbsp;This&nbsp;is&nbsp;required&nbsp;to&nbsp;set&nbsp;dirty&nbsp;and&nbsp;call&nbsp;compute  
//&nbsp;when&nbsp;the&nbsp;attribute&nbsp;editor&nbsp;values&nbsp;are&nbsp;changed.  
ATTRIBUTE\_AFFECTS(&nbsp;frustrum\_width,&nbsp;&nbsp;bboxCorner1&nbsp;);  
ATTRIBUTE\_AFFECTS(&nbsp;frustrum\_width,&nbsp;&nbsp;bboxCorner2&nbsp;);  
ATTRIBUTE\_AFFECTS(&nbsp;frustrum\_height,&nbsp;bboxCorner1&nbsp;);  
ATTRIBUTE\_AFFECTS(&nbsp;frustrum\_height,&nbsp;bboxCorner2&nbsp;);  
ATTRIBUTE\_AFFECTS(&nbsp;frustrum\_nearz,&nbsp;&nbsp;bboxCorner1&nbsp;);  
ATTRIBUTE\_AFFECTS(&nbsp;frustrum\_nearz,&nbsp;&nbsp;bboxCorner2&nbsp;);  
ATTRIBUTE\_AFFECTS(&nbsp;frustrum\_farz,&nbsp;&nbsp;&nbsp;bboxCorner1&nbsp;);  
ATTRIBUTE\_AFFECTS(&nbsp;frustrum\_farz,&nbsp;&nbsp;&nbsp;bboxCorner2&nbsp;);&nbsp;&nbsp;  
…

Then in the compute I have:

if(&nbsp;computing\_plug&nbsp;==&nbsp;bboxCorner1&nbsp;)  
&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Get&nbsp;input&nbsp;values&nbsp;from&nbsp;UI&nbsp;attributes  
&nbsp;&nbsp;&nbsp;&nbsp;MDataHandle&nbsp;handle\_w&nbsp;=&nbsp;datablock.inputValue(&nbsp;frustrum\_width,&nbsp;&stat&nbsp;);  
&nbsp;&nbsp;&nbsp;&nbsp;MDataHandle&nbsp;handle\_h&nbsp;=&nbsp;datablock.inputValue(&nbsp;frustrum\_height,&nbsp;&stat&nbsp;);  
&nbsp;&nbsp;&nbsp;&nbsp;MDataHandle&nbsp;handle\_n&nbsp;=&nbsp;datablock.inputValue(&nbsp;frustrum\_nearz,&nbsp;&stat&nbsp;);  
&nbsp;&nbsp;&nbsp;&nbsp;MDataHandle&nbsp;handle\_f&nbsp;=&nbsp;datablock.inputValue(&nbsp;frustrum\_farz,&nbsp;&stat&nbsp;);

//&nbsp;update&nbsp;bounding&nbsp;box&nbsp;co-ords  
&nbsp;&nbsp;&nbsp;&nbsp;MDataHandle&nbsp;handle\_o&nbsp;=&nbsp;datablock.outputValue(&nbsp;computing\_plug&nbsp;);  
&nbsp;&nbsp;&nbsp;&nbsp;handle\_o.set(&nbsp;-(handle\_w.asDouble()&nbsp;/&nbsp;2.0),&nbsp;-(handle\_h.asDouble()&nbsp;/&nbsp;2.0),&nbsp;-handle\_n.asDouble());  
&nbsp;&nbsp;&nbsp;&nbsp;datablock.setClean(&nbsp;computing\_plug&nbsp;);

//&nbsp;update&nbsp;camera&nbsp;frustrum draw&nbsp;co-ords  
&nbsp;&nbsp;&nbsp;&nbsp;recomputeFrustrum(&nbsp;handle\_w.asDouble(),&nbsp;handle\_h.asDouble(),&nbsp;handle\_n.asDouble(),&nbsp;handle\_f.asDouble()&nbsp;);

stat&nbsp;=&nbsp;MS::kSuccess;  
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;stat;  
&nbsp;&nbsp;}  
else&nbsp;if(&nbsp;computing\_plug&nbsp;==&nbsp;bboxCorner2&nbsp;)  
{  
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Get&nbsp;input&nbsp;values&nbsp;from&nbsp;UI&nbsp;attributes  
&nbsp;&nbsp;&nbsp;&nbsp;MDataHandle&nbsp;handle\_w&nbsp;=&nbsp;datablock.inputValue(&nbsp;frustrum\_width,&nbsp;&stat&nbsp;);  
&nbsp;&nbsp;&nbsp;&nbsp;MDataHandle&nbsp;handle\_h&nbsp;=&nbsp;datablock.inputValue(&nbsp;frustrum\_height,&nbsp;&stat&nbsp;);  
&nbsp;&nbsp;&nbsp;&nbsp;MDataHandle&nbsp;handle\_n&nbsp;=&nbsp;datablock.inputValue(&nbsp;frustrum\_nearz,&nbsp;&stat&nbsp;);  
&nbsp;&nbsp;&nbsp;&nbsp;MDataHandle&nbsp;handle\_f&nbsp;=&nbsp;datablock.inputValue(&nbsp;frustrum\_farz,&nbsp;&stat&nbsp;);

//&nbsp;update&nbsp;bounding&nbsp;box&nbsp;co-ords  
&nbsp;&nbsp;&nbsp;&nbsp;MDataHandle&nbsp;handle\_o&nbsp;=&nbsp;datablock.outputValue(&nbsp;computing\_plug&nbsp;);  
&nbsp;&nbsp;&nbsp;&nbsp;handle\_o.set(&nbsp;(handle\_w.asDouble()&nbsp;/&nbsp;2.0),&nbsp;(handle\_h.asDouble()&nbsp;/&nbsp;2.0),&nbsp;-handle\_f.asDouble()&nbsp;);  
&nbsp;&nbsp;&nbsp;&nbsp;datablock.setClean(&nbsp;computing\_plug&nbsp;);

//&nbsp;update&nbsp;camera&nbsp;draw&nbsp;co-ords  
&nbsp;&nbsp;&nbsp;&nbsp;recomputeFrustrum(&nbsp;handle\_w.asDouble(),&nbsp;handle\_h.asDouble(),&nbsp;handle\_n.asDouble(),&nbsp;handle\_f.asDouble()&nbsp;);

stat&nbsp;=&nbsp;MS::kSuccess;  
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;stat;  
}  
&nbsp;  
Where the recomputeFrustrum takes the input values for the frustrum attributes and uses them to create the vertex array to draw the camera frustrum.&nbsp;  
&nbsp;  
The vertex array edited by recomputeFrustrum is then passed through to the camera geometry for drawing:  
&nbsp;  
bool&nbsp;MyCamera::setValue(&nbsp;int&nbsp;pntInd,&nbsp;const&nbsp;MPoint&nbsp;&&nbsp;val&nbsp;)  
{  
&nbsp;&nbsp;bool&nbsp;result&nbsp;=&nbsp;false;&nbsp;&nbsp;MyCamera\*&nbsp;nonConstThis&nbsp;=&nbsp;(MyCamera\*)this;  
MyCamera\_Geom\*&nbsp;geomPtr&nbsp;=&nbsp;nonConstThis-\>cachedGeom();  
&nbsp;&nbsp;if&nbsp;(&nbsp;NULL&nbsp;!=&nbsp;geomPtr&nbsp;)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;geomPtr-\>vertices[&nbsp;pntInd&nbsp;]&nbsp;=&nbsp;val; &nbsp;&nbsp;&nbsp;&nbsp;result&nbsp;=&nbsp;true; &nbsp;&nbsp;}&nbsp;&nbsp;  
childChanged(&nbsp;MPxSurfaceShape::kBoundingBoxChanged&nbsp;);  
childChanged(&nbsp;MPxSurfaceShape::kObjectChanged&nbsp;);  
&nbsp;&nbsp;return&nbsp;result; }

I call this from postConstructor and the camera draw call.

Unfortunately the postConstructor values are not correct for the frustrum attributes.  
I’m assuming the attribute editor values haven’t been updated for that plug until after the post constructor has completed?
