4.207 Formal Design Knowledge and Programmed Constructs
Spring 2003


A Quick Guide To Using Visual LISP



Introduction

Visual LISP is a software tool designed to expedite the development of AutoLISP programs. The Visual LISP integrated development environment (IDE) provides tools to help you with editing, formatting, testing and debugging of your AutoLISP code.

To start the Visual LISP IDE, type at the AutoCAD Command Prompt:

vlisp
or using menus goto...
Tools > AutoLISP > Visual LISP Editor

Interface

  1. Text Window
    The text window is essentially a text editor built especially for AutoLISP. It does color coding and also has a formatter to automatically reformat your code to be legible. To change the color coding, with the text window active, go to Tools > Window Attributes > Configure Current.... To Change the formatting options, see the formatting code section below.

    Note: the menu selection changes depending on which window is active.

  2. Console Window
    The console window is functionally equivalent to the AutoCAD text screen except that it has some added features to help with the development of your AutoLISP code. You can type AutoLISP expressions directly into the console window and they will be executed in AutoCAD. The console window also remembers the list of expressions entered and the previous command can by retrieved by pressing Tab. To go forwards in the list press Shift-Tab. Right-Click in the console window will bring up a menu with shortcuts of often used functions.

  3. Trace Window
    The trace window allows you to record debugging information into a file. To turn tracing on, Right-Click in the trace window and select Toggle Trace Log...

  4. Loading Code
    After typing in your code you will want to load it into AutoCAD. You can do this in two ways; click on the load icon (see below) or by typing the appropriate expression in the console window.
    Loads the code in the text window into AutoCAD.
    Loads only the selected code in the text window into AutoCAD.

  5. Checking Code
    Visual LISP provides a checker that checks to see if your program is syntatically correct. It checks for things like matching parenthesis, correct number of arguments, and proper usage of reserve words. The result of the check will be displayed in the Build Output window. (see Debugging section below)
    Checks the code in the text window for syntatic errors.
    Checks only the selected code in the text window for syntatic errors.

  6. Formatting Code
    Visual LISP provides you with a code formatter that automatically reformats your AutoLISP code into a more legible format. You can control the formatting options in Options > Visual LISP Format Options....
    Formats all of the code in the text window.
    Formats only the selected code in the text window.


Debugging

  1. Environment Settup
    To setup up debugging feature for top level commands:
    Tools-> Environment Option ->General Option -> Diagnostic
    uncheck "do not debug top level"You have to do this to allow debugging for batch commands

  2. Parenthesis Matching
    Ctrl-]Match Forward
    Ctrl-[ Match Backward
    Ctrl-Shift-] Match Select Forward
    Ctrl-Shift-[ Match Select Backward

  3. Build Output Window
    Double-click the highlighted error message in the < Build Output > window and the expression in error will be highlighted in the text window.

  4. Adding Watch
    The watch list allows you to examine the value of a variable during execution. To bring up the watch window, click on . To add a variable to the watch list, type Ctrl-W or click on the icon. When prompted, type in the variable name you wish to watch.

  5. Inspecting
    In addition to just watching the variable, you can also inspect it. By double-clicking on a variable in the watch window, you can get even more detailed information about that variable. Alternatively, you can also click on icon and enter a variable name.

  6. Error Trace
    Sometimes an error occurs in your program and you have no idea what part of the code is causing the problem. Visual LISP provides you with a tool to pinpoint errors it finds. Goto View>Error Trace and a new Error Trace window should appear. Find the LISP statement just below the first error message. Right click on the LISP statement and select "Call point source". The problematic code should be highlighted in your text window.

  7. Toggle Breakpoints
    Breakpoints allow you to mark a position in the program at which program execution should be interrupted. You can then step through the program part by part. To place a breakpoint, position the cursor where you want the breakpoint and click on or press F9. You can remove the breakpoints in a similar fashion. To view all the breakpoints you can type Ctrl-Shift-B or in the menu goto View > Breakpoints Window. After placing a breakpoint, load the code. Once Visual LISP encounters a breakpoint, it will pause the evaluation of the program. At this point 6 new debugging icons appear.
    [Step Into] Jumps into a nested expression, if any. If there is no nested expressions, it jumps to the next expression in sequence.
    [Step Over] Looks for the close parenthesis matching the open parenthesis where the program is currently paused, and evaluates the expressions in between.
    [Steps Out] searches for the end of the function where the program is currently paused, and evaluates all the expressions up to that point.
    [Continue] Resumes normal program execution from the breakpoint.
    [Quit Current Level] Terminates the current break loop and returns to a break loop one level up. This may be another break loop or the top-level read-eval-print loop.
    [Reset to Top Level] Terminates all currently active break loops and returns to the top read-eval-print loop. In other words, stop debugging.

    During debugging mode, you can also change the value of any variable in the program through the console window. Simply set the value of the variable to the desired value. Ex. (setq width 100)

    Note: To break into debugging mode without using a breakpoint goto Debug > Stop Once. Once you load the program, it will start the debug mode at the first expression Visual LISP encounters.

  8. Animate Mode
    Another "nifty" feature of Visual LISP is the animate mode. During the animate mode, Visual LISP steps through your code and evaluates each expression automatically. To turn on/off the animate mode, goto Debug > Animate. Now load the program you want to animate via the the Visual LISP console window or the load icons. Visual LISP will then hightlight each expression it evaluates as it goes through your program. I would suggest dividing your screen so that the Visual LISP window sits next to the AutoCAD window. That way, you can see the results of your program on the screen as well. To stop the animation, press Break. To adjust the rate of the animation, goto Tools > Environment Options > General Options > Diagnostic and adjust the Animation Delay settings (in milliseconds).

  9. Commenting and Uncommenting
    You may turn a line of text into comment so that it will be skipped by AutoLISP, or uncomment it back to a part of your program. This is sometimes very useful for debugging.
    [comment] Turn the selected lines into comments by adding semi-colon(s).
    [uncomment] Uncomment the selected lines.




Send questions and comments to takehiko@mit.edu
Revised: 02/05/2007