Mel Script - Common Dialog Boxes




There are a set of simple little dialog boxes that can be used to request user input, or to provide some message to the user.







File Dialogs

Detailed in the following page.







Colour Selected Dialog

The following example creates a colour selection dialog box. Use it whenever you want the user to be able to specify a colour.



		// create a colour editor dialog box
		// query the result
		if (`colorEditor -query -result`) {
			float $rgb[], $alpha;
			// get RGB
			$rgb = `colorEditor -query -rgb`;
			print("Colour = "+ $rgb[0] +" "+ $rgb[1] +" "+ $rgb[2] +"\n");
			// get alpha
			$alpha = `colorEditor -query -alpha`;
			print("Alpha  = "+ $alpha +"\n");
		} else {
			print("Editor was dismissed\n");





Confirm Dialog

The mel command confirmDialog brings up a simple little yes/no; ok/cancel type of dialog box. Simply check the return argument from the command to see what was chosen.



		// create a confirm dialog with a yes and no button. Specif
		$response = `confirmDialog -title "Confirm" 
			              -message "Yes or No? It's your choice..."
			              -button "Yes" 
			              -button "No"
			              -defaultButton "Yes"
			              -cancelButton "No"
			              -dismissString "No"`;
		// check response	  
		if( $response == "Yes" ) {
			print("User says yes\n");
		} else if( $response == "No" ) {
			print("User says no\n");





Font Dialog

The mel command fontDialog allows you to request a specific font. It is my understanding that this only works on Windows, but i shall check later. The returned argument from font dialog is the name of the font selected.



		// create a font dialog and store the chosen font
		// in the $font_name variable
		$font_name = `fontDialog`;
		// print selected font
		print( "font selected \"" + $font_name + "\"\n" );				  





Prompt Dialog

The prompt dialog in mel allows you to bring up a small window into which can be used to request a specific value from the user.



		string $text;
		// create a prompt dialog to request the users name
		string $result = `promptDialog 
			-title "Hello Window"
			-message "Enter Name:"
			-button "OK" -button "Cancel"
			-defaultButton "OK" -cancelButton "Cancel"
			-dismissString "Cancel"`;
	 	// if OK pressed
		if ($result == "OK") {
			// query the entry typed by the user
			$text = `promptDialog -query -text`;
			print("HELLO to "+ $text +"\n");
		else {
			print("fine. I won't say hello then :(\n");





Related Documents

Windows & A quick GUI overview




Attribute Controls