Signaling with error, warning, and trace

error

The error command prints an error message in standard MEL format and stops the script:

$l = `ls -lights`;
if (size($l) == 0) {
	error "No lights in scene";
}

This will produce the following output and stop execution:

// Error: No lights in scene //

warning

The warning command prints a warning message in standard MEL format but does not stop the script:

$l = `ls -lights`;
if (size($l) == 0) {
	warning "No lights in scene";
}

This will produce the following output:

// Warning: No lights in scene //

The error and warning commands have a flag -showLineNumber. Set the flag to true to show the file and line number in which the warning or error occurred. Set the flag to false to suppress line numbers.

warning -showLineNumber true "No lights";
// Warning: file: C:\test.mel line 2: No lights //

trace

The trace command prints a string to Maya’s standard error output.

trace "Entering the loop";
while ($i < 10) {
	setAttr("nurbsSphere"+$i+".translateX",5);
}
trace "Exiting the loop";

Use the -where flag to show the file and line number in which the trace command occurred in the output.