Debugging MEL Scripts

If you were careful entering the commands in the last chapter, you may have gotten away without seeing a MEL error; in the work ahead, however (and certainly as you begin building MEL scripts of your own), you will encounter errors, the most common of which is the syntax error. Every command has a particular structure or form that needs to be followed in order to execute successfully. Otherwise, the script interpreter wonnt know what to do with your command and will most often return a syntax error.

While debugging a script is a bit of an art form, there are a couple of ways you can help yourself. First, check the History window when you execute a script: If the last line of your script is the last line of the History window, the commands executed without an error. If, however, you get a comment line like the following:

setAttr tire 5;

//Error: line 1: No attribute was specified. // you know that there has been at least one error in parsing the script.

Note Parsing is the programming term for the search the script interpreter does through the script to make sure all the commands are correct.

The Feedback line (at the bottom-right of the screen) will also turn orange-red to indicate that the MEL interpreter has discovered an error in your code. One way to help you quickly identify where these errors might lie is by turning on the Edit > Show Line Numbers option in the Script Editor menu. Generally, itns a good idea to keep this option on at all times, as it does not slow Maya down in any way, and it provides useful information about where errors are occurring.

As you begin scripting, one error that will probably creep in is forgetting the final semicolon at the end of each line. This can be difficult to spot if younre not aware of the problem. If you are getting errors in your script that donnt make sense, try looking at each line of code to be sure it finishes with a semicolon.

Finally, since MEL is an interpreted scripting language, you can execute a script one line at a time, rather than as a whole. This can be a very useful way to figure out where a problem is occurring in your program. A brief exercise will illustrate:

1. Type in the following, but donnt execute it yet:

print hello, world! ; print hello, world;

  1. Now highlight the first line and execute it (by pressing the Enter key on your numeric keypad). You should see hello, world! printed out in the History window.
  2. Now highlight and execute the second line. You should see something like the following:

// Error: print hello, world; // // Error: Line 1.12: Syntax error //

The first line executed properly, but the second had an error in itnthe print command needs a string to work with, and you need to include quote marks to identify the string. In a two-line script, spotting the error would be simple; in a longer script, this method of going through the script one line at a time can be a great way of uncovering problem spots.

  1. We know how to get help and debug a scriptnnow letns get down to business! -—--- Mi>
  2. com, Inc. © 2000 - Feedback

0 0

Post a comment

  • Receive news updates via email from this site