AE template update optionMenu

Hi there all, Im creating a scripted node in with python and one of the attributes is a messageAttr witch i want to show in the AE ad an option  menu of a list of maya cameras, so far i have this (amongts many otehr things) in the AE...template 

editorTemplate -callCustom "AE\_custom\_camera\_menu" "AE\_edit\_custom\_camera\_menu" "camera";

global proc AE\_custom\_camera\_menu(string $attr){
      rowLayout -nc 3;
         text -label "Camera"
         optionMenu -width 200;
         string $str[] = `ls -cameras`;
         int $i;
         for ($i = `size($str)`; $i > 0; $i--){
            menuItem -label $str[$i-1];         
         }
} 

so this populates the list just fine but i cant figure out or find any documentation on how to update the contents of the optio menu. Presumably i would want to create some sort of procedure that gets called when the menu is clicked, but even if i could figure out how to make the procedure get triggered i woudlnt know how to access the option menu usually i would assign it to a global variable but thats out of the question as i may have many instances of the node in my scene, any ideas how I'd do this?

Thanks

jt 

Well allmost certainly do not want the first and the second procedure the same. At minimum you want the second call custom argument be calling the first after a global reset of the guitem.

so this populates the list just fine but i cant figure out or find any documentation
on how to update the contents of the optio menu.

that would be the job of the second callcustom argument.

Presumably i would want to create some sort of procedure that gets called when the menu is clicked,

No don't do that you dont need it. Update the menu when the AEtemplate is made with the second procedure in callcustom. You shoudl look into AEcameraTemplate.mel for a good example

i woudlnt know how to access the option menu

well your a bit missuaing the attr thing, usually you want to pass $nodeName- Anyway usually you dont need to because you give a name to the meuitem you make, example:

global proc AElocatorTemplate( string $nodeName )
{
 
	editorTemplate -beginScrollLayout;
 
		editorTemplate -beginLayout (uiRes("m_AElocatorTemplate.kLocatorAttributes")) -collapse 0;
			editorTemplate -callCustom "AE_custom_camera_menu_create" "AE_custom_camera_menu_edit" $nodeName;
			AElocatorCommon $nodeName;
		editorTemplate -endLayout;
 
		AElocatorInclude $nodeName;
 
	editorTemplate -addExtraControls;
	editorTemplate -endScrollLayout;
 
}
 
global proc AE_custom_camera_menu_create(string $attr){
         optionMenuGrp -label "Cameras" jooAeCustomCameraMenuItem;
         string $cameras[] = `ls -cameras`;
         for ($item in $cameras){
              menuItem -label $item;         
         }
}
 
global proc AE_custom_camera_menu_edit(string $attr){
    deleteUI jooAeCustomCameraMenuItem;       
    AE_custom_camera_menu_create($attr);
}

usually i would assign it to a global variable

then your usually doing things wrong, people almost instinctively use globals far too much, in 90% of cases theres really no meed for global even in cases that are shipped in autodesks built-in scripts. remeber names are global no matter what.

EDIT: made script simpler

Hi jooj , thats great but i still have aproblem. The dropdown menu resets itself each time i select the node, and it seems like when i create a second instance of the node and change the menus value it also changes the value of the other menu... heres my code now

// procedures for camera option menu
global proc AE\_custom\_camera\_menu\_create(string $attr){
optionMenuGrp -label "Cameras" jooAeCustomCameraMenuItem;
string $cameras[] = `ls -cameras`;
for ($item in $cameras){
menuItem -label $item;
}
}
global proc AE\_custom\_camera\_menu\_edit(string $attr){
deleteUI jooAeCustomCameraMenuItem;
AE\_custom\_camera\_menu\_create($attr);
}
// layout definition ---------------------------------------------------------
global proc AEms\_renderSettingsTemplate(string $nodeName)
{
editorTemplate -beginScrollLayout;
editorTemplate -beginLayout "Export settings" -collapse false;
editorTemplate -callCustom "AE\_file\_browse" "AE\_file\_browse\_repeat" "output\_directory";
editorTemplate -addControl "output\_file";
editorTemplate -endLayout;
editorTemplate -beginLayout "Camera settings" -collapse true;
editorTemplate -addControl "export\_all\_cameras";
editorTemplate -addSeparator;
editorTemplate -addControl "export\_all\_cameras\_as\_thinlens";
editorTemplate -endLayout;
editorTemplate -beginLayout "Assembly settings" -collapse true;
editorTemplate -addControl "interpret\_sets\_as\_assemblies";
editorTemplate -addSeparator;
editorTemplate -addControl "double\_sided\_shading";
editorTemplate -endLayout;
editorTemplate -beginLayout "Output settings" (uiRes("m\_AElocatorTemplate.kLocatorAttributes")) -collapse true;
AElocatorCommon $nodeName;
editorTemplate -callCustom "AE\_custom\_camera\_menu\_create" "AE\_custom\_camera\_menu\_edit" $nodeName;
editorTemplate -addControl "color\_space";
editorTemplate -endLayout;
editorTemplate -beginLayout "Configuration settings" -collapse true;
editorTemplate -addControl "export\_custom\_interactive\_config";
editorTemplate -addControl "interactive\_lighting\_engine";
editorTemplate -addControl "interactive\_min\_samples";
editorTemplate -addControl "interactive\_max\_samples";
editorTemplate -addControl "interactive\_max\_ray\_depth";
editorTemplate -addControl "interactive\_light\_samples";
editorTemplate -addSeparator;
editorTemplate -addControl "export\_custom\_final\_config";
editorTemplate -addControl "final\_lighting\_engine";
editorTemplate -addControl "final\_min\_samples";
editorTemplate -addControl "final\_max\_samples";
editorTemplate -addControl "final\_max\_ray\_depth";
editorTemplate -addControl "final\_light\_samples";
editorTemplate -endLayout;
AEdependNodeTemplate $nodeName; // add any base class attributes
editorTemplate -addExtraControls; // add any other attributes
//editorTemplate -suppress "attrbute";
editorTemplate -endScrollLayout;
}

any idea whats happening?

thanks
jt 

Well obviously if you need the data to be stored you need to connect the guitem to an attribute somehow, i was just doing what you were doing. That is making a gui item without actually making it do anything. Use a -changeCommand script to make the control do some persistent changes in the node and the edit proc update the values after they've been created to mach the selection.

No time to do anything about this today.

aaah i thik i get it, its obvious if you know how :stuck_out_tongue:  ill give it  atry but im sure ill still be trying in the morning :slight_smile: so if you have any hints 

jt 

Hi there again, so ive gotten the optionMenu working but i want to add a button beside it now to create soe custom nodes. The problem I'm having now is that i have a button with a -command that i want to call but I need so send an attribute to the procedure that i want to call and im not sure how. So heres an example

string $attr = "some text";

button -label "labelTexxt" -c "myProc($Attr)";
global proc myProc($attr){
    print $attr;
}

so in  this example the i get an error, so im assuming that im defining the command wrongly. Theres the actual code im having the problem with 

// procedures for environment option menu
global proc AEcustomEnvironmentMenuCreate(string $attr){
   // get actual node name
   string $nodeNameTokens[];
   tokenize $attr "." $nodeNameTokens;
   int $newStringLength = size($nodeNameTokens[0]);
   string $nodeName = `substring $nodeNameTokens[0] 1 $newStringLength`;
   string $currentCameraConnection = `getConnectedNode($nodeName + ".environment")`;
   string $customCameraMenuCommand = "setEnvironmentConnection " + $nodeName;
   optionMenuGrp -label "Environmnets" -cc $customCameraMenuCommand -w 300 customEnvironmentMenu;
   string $environments[] = `ls -type "ms\_environment"`;
   menuItem -label "<none>";
   for ($item in $environments){
        menuItem -label $item;         
   }
   string $buttonCommand = "createMsEnvironmentNode($nodeName)";
   button -l "+" -h 20 -w 30 -c $buttonCommand -p customEnvironmentMenu;
}
global proc AEcustomEnvironmentMenuEdit(string $nodeName){
    deleteUI customEnvironmentMenu;       
    AEcustomEnvironmentMenuCreate($nodeName);
}
global proc setEnvironmentConnection(string $nodeName){
   string $newSelection = `optionMenuGrp -q -v customEnvironmentMenu`;
   $newSelectionAttr = $newSelection + ".nodeState";
   string $environmentConnectionName = $nodeName + ".environment";
   string $currentEnvironmentConnection = `getConnectedNode($nodeName + ".environment")`;
   if ($currentEnvironmentConnection != ""){
      $currentEnvironmentConnection = $currentEnvironmentConnection + ".nodeState";
      disconnectAttr $currentEnvironmentConnection $environmentConnectionName;
   }
   if ($newSelection != "<none>"){
      connectAttr $newSelectionAttr $environmentConnectionName;      
   }
}
global proc createMsEnvironmentNode(string $nodeName){
   print "something";
   createNode "ms\_environment" -ss;
   AEcustomEnvironmentMenuEdit($nodeName);
}

any ideas what im doing wrong/should do

Thanks

jt 

my bad, jiust realised my syntax was off, should be:

button -label "labelTexxt" -c ("myProc " + $attr);
global proc myProc($attr){
    print $attr;
}

jt