I’m adding custom ramp attribute to light nodes and having problems with attribute editor display.
If AttributeEditor is already open and displaying some content, when I create new light, custom attrs are added after AE redraw.
This messes AE because it want’s to draw ramp attribute that doesn’t exists yet.
If light is created before AE open, everything displays correctly, even subsequent light creations - so this has smth. to do with AE initialization/caching …
Currently I use scriptJob to add attributes:
scriptJob -permanent -e DagObjectCreated “AddExtraLightAttrs”;
I’ve been using scriptJob for some time now and never had any issues with attributes other than a ramp.
What can I do to fix this? Is there better alternative to scriptJob?
I did a quick test with registering an API callback: OpenMaya.MDGMessage.addNodeAddedCallback which in turn calls a AddExtraLightAttrs MEL, but this doesn’t seem to fix this.
Or maybe I can make light AETemplate more bulletproof.
I’ve also heard that new Maya allows to subclass lights to better handle custom attrs, but I couldn’t find any docs for that.
I’m stuck with this, so any hint is welcome.
Below is code that adds a ramp attr and part of modified AEspotLightTemplate:
proc AddExtraLightAttrs_Ramp(string $node)
{
//color ramp
addAttr -longName "ColorGradient" -attributeType "compound" -multi -numberOfChildren 3 $node;
addAttr -shortName "ColorGradient_Position" -attributeType "float" -parent "ColorGradient" $node;
addAttr -shortName "ColorGradient_Color" -attributeType float3 -storable 1 -parent "ColorGradient" $node;
addAttr -shortName "ColorGradient_ColorR" -attributeType "float" -parent "ColorGradient_Color" $node;
addAttr -shortName "ColorGradient_ColorG" -attributeType "float" -parent "ColorGradient_Color" $node;
addAttr -shortName "ColorGradient_ColorB" -attributeType "float" -parent "ColorGradient_Color" $node;
addAttr -shortName "ColorGradient_Interp" -attributeType "enum" -enumName "None:Linear:Spline:Smooth" -parent "ColorGradient" $node;
//ramp index type
addAttr -longName "ColorGradientInput" -attributeType "enum" -enumName "Distance:Intensity:Angle:IntensityAngle" $node;
addAttr -longName "ColorGradientInputMaxPoint" -attributeType "float" $node;
addAttr -longName "ColorGradientMix" -attributeType "float"$node;
setAttr ($node + ".ColorGradientInputMaxPoint") 1;
}
global proc AEspotLightTemplate ( string $nodeName )
{
AEswatchDisplay $nodeName;
editorTemplate -callCustom
("AEspotLightPreviewPortNew " + $nodeName )
("AEspotLightPreviewPortReplace " + $nodeName )
"coneAngle";
editorTemplate -beginScrollLayout;
editorTemplate -beginLayout (uiRes("m_AEspotLightTemplate.kSpotLightAttr")) -collapse 0;
AElightCommon $nodeName;
// THIS PART IS NEW
editorTemplate -beginLayout "Colour Gradient" -collapse 0;
AEaddRampControl($nodeName + ".ColorGradient");
editorTemplate -addControl "ColorGradientInput";
editorTemplate -addControl "ColorGradientInputMaxPoint";
editorTemplate -callCustom "AEmfdlSlider_New" "AEmfdlSlider_Replace" "ColorGradientMix 0 1";
editorTemplate -endLayout;
// REST OF FILE IS ORIGINAL
PS. this is re-post from maya-python grp, but I didn’t get any responses, hope you don’t mind.