MEL File Browser with text box


#1

Hey guys,

I’ve been trying to figure out this one for a little while, and I’m still pretty new to MEL scripting so I’m not even sure I’m going about this the right way. I’m trying to create a text field in a MEL window for a user to enter a file directory. I want to have a “browse” button next to it which they can use to find a file and it’s directory, and then have the string which is returned entered into the text field. Right now my process looks like this:

//browse procedure
 proc browseFiles( ) {
 		  $browseFiles = `fileDialog2 -fm 1`;
 }
 
 // creates window with controls for user
 if (`window -exists ctrlWindow`) deleteUI ctrlWindow;
 if (`windowPref -exists ctrlWindow`) windowPref -remove ctrlWindow;
 window -title "MatteShader" -widthHeight 275 425 ctrlWindow;
 
 string $browseFiles = "";
 
 rowLayout  -numberOfColumns 4 -width 350;	
 		textField -w 200 -tx "" colPath;
 		button -label "Browse" -w 50 -command "browseFiles()";	 
 		setParent ..;
 
 setParent ..;
 showWindow ctrlWindow;
 

So in my mind what I’m trying to do is update the textField box with the $broseFiles string after the button is pressed and the file has been selected…but I can’t figure out a way to update a textField. Is there a better way of going about this whole process?

Thanks for any help!
Jesse


#2

hi,

would something like this work?

//browse procedure
 proc browseFiles( ) {
		   textField -edit -text `fileDialog2 -fm 1` myTextField;
 }
 
 // creates window with controls for user
 if (`window -exists ctrlWindow`) deleteUI ctrlWindow;
 if (`windowPref -exists ctrlWindow`) windowPref -remove ctrlWindow;
 window -title "MatteShader" -widthHeight 275 425 ctrlWindow;
 
 string $browseFiles = "";
 
 rowLayout  -numberOfColumns 4 -width 350;	
		 textField -w 200 -tx "" myTextField;
		 button -label "Browse" -w 50 -command "browseFiles()";	 
		 setParent ..;
 
 setParent ..;
 showWindow ctrlWindow;

#3

to edit any control you just do:
controlCommand -edit -flagYouWantToEdit “newValue” controlName;
so, in your example, something like this should do:

// browse procedure
global proc browseFiles( )
 {
 	string $file = `fileDialog -m 0`;
 	textField -edit -tx $file colPath;
 }
 

so you are basically just editing the textField -text after getting the name from the fileDialog command. (btw, I only have 2010, so I have no idea what the fileDialog2 command is… I’ve just used fileDialog in this example, but the idea should be the same on your side).

:nathaN


#4

fileDialog2 has superseded fileDialog and fileBrowserDialog, rendering both obsolete and deprecated as of Maya 201?.


#5

Thanks guys, those seem to work great! I had seen that sort of coding around before to edit the control command, but didn’t realize exactly what it was doing. Thanks for the examples and the explanation behind it (one more small piece of MEL mystery unveiled…)

And yeah, apparently fileDialog2 is the new command…the others are currently compatible with 2011 but won’t be with future versions of maya.

Jesse


#6

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.