Mel - Maya Embedded Language

Windows are a nice way to package your MELscripts. Using windows allows the user to input / change data used by your MEL scripts on the fly. They can also be useful for making list of commonly used commands. If we did not use a window to process our procedures, the user would have to either type in the variable's value when calling the procedure or they would have to edit the variables value in the MEL script before using it.

-creating windows

This is the core of writing a window. Every window must start with this command

      window windowName;

In order to have the window show you must call this command. Call this command after you have writing everything you want to go into your window.

      showWindow windowName;
-deleting old windows.

In order to open a window again. you need to delete the window. You should also remove the preference file associated with the window. Place this code before the window command.

      if (`window -exists windowName`)
           deleteUI windowName;
           windowPref -remove windowName;

Putting it all together:
if (`window -exists myWin1`)
     {           deleteUI myWin1;
          windowPref -remove myWin1;
window myWin1;
showWindow myWin1;
Use the following attributes to position and size your windows

      window -width int windowName;
      window -height int windowName;
      window -widthheight int int windowName;
      window -topEdge int windowName;
      window -leftEdge int windowName;
      window -topLeftCorner int int windowName;

Example: window -topEdge 100 myWin1;
Exercise: Open a basic window and set the width, height and topLeftCorner. Change the code to move the window to the bottom right corner of your screen.

-popup windows

     1). promptDialog


string $text;
string $result = `promptDialog
     -title "My New Prompt Window"
     -message "Enter Something:"
     -button "OK" -button "Cancel"
     -defaultButton "OK" -cancelButton "Cancel"
     -dismissString "Cancel"`;

if ($result == "OK")
     $text = `promptDialog -query -text`;
     print $text;

     2). confirmDialog

string $yourAnswer = `confirmDialog -title "Confirm Dialog" -message "Do you love MEL?"
-button "Yes" -button "No" -defaultButton "Yes"
-cancelButton "No" -dismissString "No"`;

if ($yourAnswer == "Yes")
     print ("Yeah!");
     print ("What did you say?");