Tuesday 8 March 2011

Maya AE Template File Browser

Ok, I slept on it and I've been able to make the MEL end of the file browser work properly!


I was close before, just turns out my MEL is rusty and I didn't realize I could have a variable at the end of control declarations for use later on when I want to update the display.

Today's problem:

I want to attach a file browser to my node's string attribute.

Today's solution:

As far as I can tell, the only way to have controls other than simple attribute input/outputs is by using the callCustom command. Here's some code:

The main template function
global proc AEADANodeTemplate( string $nodeName )
{
 editorTemplate -beginScrollLayout;
 
 //File Attributes
 editorTemplate -beginLayout "File Attributes" -collapse 0;
  editorTemplate -addControl "input";
  editorTemplate -callCustom "AE_file_browse" //create the file browser
         "AE_file_browse_repeat" //update the file browser
         "AudioFile"; //file location attribute
  editorTemplate -addControl "SampW";
  editorTemplate -addControl "FrameR";
  editorTemplate -addControl "NFrames";
  editorTemplate -addControl "NChan";
 editorTemplate -endLayout;
 
 //Amplitude
 editorTemplate -beginLayout "Amplitude" -collapse 0;
  editorTemplate -addControl "amplitudeL";
  editorTemplate -addControl "amplitudeR"; 
 editorTemplate -endLayout;
 
 AEdependNodeTemplate $nodeName;
 
 editorTemplate -addExtraControls;
 editorTemplate -endScrollLayout;
}

The browser functions
global proc AE_file_browse(string $attr){
 
 rowLayout -nc 3;
  text -label "Audio File";
  textField  -fileName `getAttr $attr` LocationText;
  symbolButton -image "navButtonBrowse.xpm" -c ("loadPopup(\"" + $attr + "\")");
  setParent ..;
 
}

global proc AE_file_browse_repeat(string $attr){
 textField  -e -fileName `getAttr $attr` LocationText;
}

The browser popup function
global proc loadPopup(string $attr){
 string $loc = `fileDialog -dm "*.wav"`;
 
 if ($loc != ""){
  setAttr -type "string" $attr $loc;
  textField -e -fileName `getAttr $attr` LocationText;
 }
}

And that's all there is to it. I still need to fix up the Python side of things so the file is loaded once the file path has been chosen.

No comments:

Post a Comment