PDA

View Full Version : a question about update UI in AE*Template


yaoyansi
08-21-2012, 07:15 AM
Hi all,
I encounter a problem when I update UI in AETemplate dynamically.
Here is the code:
If $rnd is set to "A", when I switch to UI AESurfaceTemplate, I want to show test_plug0 in AETemplate,
and if $rnd is set to "B", when I switch to UI AESurfaceTemplate, I want to show test_plug1 in AETemplate.

//===========================================================
global proc AESurfaceTemplate( string $nodeName )
{
layout -e -vis false "AEcontrolFormLayout";
editorTemplate -beginScrollLayout;
//------ try to call special callback functions -----------
editorTemplate -beginLayout "XXX" -collapse 0;
editorTemplate -ccu ("ShaderNodesCBNew "+$nodeName) ("ShaderNodesCBReplace "+$nodeName) "rmanShaderLong";
editorTemplate -endLayout;
//----------------------------------------------------------------------------------
editorTemplate -addExtraControls;
editorTemplate -endScrollLayout;
layout -e -vis true "AEcontrolFormLayout";
}
//===========================================================
global proc ShaderNodesCBNew(string $attributeName1, string $attributeName2)
{
global string $rnd ;
string $fn;
$fn = "AEShaderTemplate_"+$rnd+"(\""+$attributeName1+"\")";
eval($fn);
}
//===========================================================
global proc ShaderNodesCBReplace(string $attributeName1, string $attributeName2)
{
global string $rnd ;
string $fn;
$fn = "AEShaderTemplate_"+$rnd+"(\""+$attributeName1+"\")";
eval($fn);
}
//===========================================================
global proc AEShaderTemplate_A( string $nodeName )
{
editorTemplate -beginLayout "AAA";
editorTemplate -addControl "test_plug0";
editorTemplate -endLayout;
}
//===========================================================
global proc AEShaderTemplate_B( string $nodeName )
{
editorTemplate -beginLayout "BBB";
editorTemplate -addControl "test_plug1";
editorTemplate -endLayout;
}

When I set $rnd to "A", and switch to AESurfaceTemplate, the function ShaderNodesCBNew() is called, but the problem is the UI is not updated at all,
"test_plug0" is not displayed in AESurfaceTemplate panel.
So, my question is:
1.Is it possible to do this in Maya?
2.If it is possible, how to do it? Could you give any clue?
Any suggestion is appreciated, and thank you in advance.

Best Regards
yaoyansi

Azrail
08-21-2012, 11:01 AM
I don't think you can use the 'editorTemplate' commands outside of the main template procedure.
The way I deal with these things is either create some layout (column, scroll, whatever), which you can clean and repopulate in your AEReplace... procedure, or just create some named control like an attrControlGrp, and then change the label and the attribute, connected to it in the AEReplace... procedure

yaoyansi
08-21-2012, 11:43 AM
I don't think you can use the 'editorTemplate' commands outside of the main template procedure.
The way I deal with these things is either create some layout (column, scroll, whatever), which you can clean and repopulate in your AEReplace... procedure, or just create some named control like an attrControlGrp, and then change the label and the attribute, connected to it in the AEReplace... procedure
Thanks for your reply, Azrail.
I can understand your words, but I'm not sure I know every detail. And I think I have to find or implement the code to decide which one is best for me.
So, could you give me a simple demo for the two methods? or could you tell me where I can find the simple demo for these methods?

Azrail
08-21-2012, 12:16 PM
Here is a quick, untested example - i just create a control in the *New* callback for your attribute, with a name that I can use later in the *Replace* callback to attach the control to another attribute. Hope that works.

//================================================== =========
global proc AESurfaceTemplate( string $nodeName )
{
layout -e -vis false "AEcontrolFormLayout";
editorTemplate -beginScrollLayout;
//------ try to call special callback functions -----------
editorTemplate -beginLayout "XXX" -collapse 0;
editorTemplate -ccu ("ShaderNodesCBNew "+$nodeName) ("ShaderNodesCBReplace "+$nodeName) "rmanShaderLong";
editorTemplate -endLayout;
//----------------------------------------------------------------------------------
editorTemplate -addExtraControls;
editorTemplate -endScrollLayout;
layout -e -vis true "AEcontrolFormLayout";
}
//================================================== =========
global proc ShaderNodesCBNew(string $attributeName1, string $attributeName2)
{
// Retrieve the name of the node and the attribute: node.attribute => {"name", "attribute"}
string $names[] = stringToStringArray($attributeName1, ".");
// Create some control with a name you can use later:
attrControlGrp -l interToUI($names[1]) -a $attributeName1 ($names[0]+"_"+$names[1] + "_Ctrl");
}
//================================================== =========
global proc ShaderNodesCBReplace(string $attributeName1, string $attributeName2)
{
global string $rnd ;
// Retrieve the name of the node and the attribute: node.attribute => {"name", "attribute"}
string $names[] = stringToStringArray($attributeName1, ".");
$newAttr = ($rnd == "A") ? "test_plug0" : "test_plug1";
// Attach the control to the new attribute and change it's label:
attrControlGrp -e -l interToUI($newAttr) -a $newAttr ($names[0]+"_"+$names[1] + "_Ctrl");
}

yaoyansi
08-21-2012, 05:00 PM
Thank you, Azrail. I will test it.


And, I also find a command in maya2012: refreshEditorTemplates
The offical doc says:
This command refreshes all cached attribute editor templates, including those copied from the standard AE. This is useful if attribute elements have changed and the templates need to be re-evaluated accordingly.

I guess it would make the work much easier. What's your opinion about this command?

CGTalk Moderation
08-21-2012, 05:00 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.