Adding custom attributes - attribute editor problems

76 views
Skip to first unread message

Michał Frątczak

unread,
Oct 30, 2014, 6:30:55 AM10/30/14
to python_in...@googlegroups.com
I'm adding custom attributes to light nodes and having problems with attribute editor.
Currently I use: 
scriptJob -permanent -e DagObjectCreated "AddExtraLightAttrs";

If AttributeEditor is already open when I create new light, new attrs are added _after_ AE refresh - this results in total mess in AE.
If light is created before AE open, everything displays correctly, even subsequent light creations - so this has smth. to do with AE initialization/caching ...

I've used this technique in the past, but now I create ramp attributes, which seem to be causing trouble.

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.

This is the code that adds a ramp attr:


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;
}





And this is part of modified AEspotLightTemplate:


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



Reply all
Reply to author
Forward
0 new messages