2009

Table Of Contents
The exists flag of the window command changes the command so that
it either returns a one or zero depending on whether or not the window
exists.
3 Type the following in the Script Editor:
deleteUI non_existing_window; sphere;
An error is output to the Script Editor.
// Error: line 1: Object not found: non_existing_window
The sphere command does not execute as the script has halted on the
scripting error.
To be able to delete the existing user interface only if it exists, conditional
statements can be used.
To delete a window on condition
1 Type the following in a MEL tab of the Script Editor:
window testwindow; fake_command; showWindow;
The window is invisible as there is a scripting error, and the showWindow
command did not execute.
2 Type the following in a MEL tab of the Script Editor:
if (`window -exists testwindow`==1) { deleteUI testwindow; }
window -resizeToFitChildren 1 testwindow; columnLayout; text
-label "This window deleted the other one"; showWindow;
Two concepts are being introduced here:
The if statement allows a certain part of code to execute depending on a
condition. The section of code within the curly braces only executes if the
statement inside the parentheses evaluates to true.
The paired back-ticks within the parentheses (` `) indicate that the
commands within them are evaluated first. This is a useful part of writing
MEL code: you can make certain commands (here, the conditional
statement) dependent on other commands (here, the evaluation of whether
the window exists), which execute and evaluate first.
628 | Chapter 13 Scripting in Maya