AfraLISP - Learn AutoLISP for AutoCAD productivity

The Visual LISP Editor - Part 1

by Kenny Ramage

This tutorial is a crash course in using the Visual LISP Editor, and is not intended to be detailed or fully comprehensive. The aim is to show you the main functions of the Editor with the intention of getting you up and running as quickly as possible.

Right, enough waffle, let's get started. Fire up AutoCAD and open a new drawing. Now choose ToolsAutoLISPVisual LISP Editor from the pull-down menu. If you don't see the pull-down menu, enter menubar at the command prompt and set the value to 1.

The Visual Lisp Editor will open and should look like this :

Visual LISP Editor

Let's start off by having a look at the Visual LISP Console window :

Visual LISP Console window

The VLISP Console window is similar in some respects to the AutoCAD Command window, but has a few extra features. You enter text into the Console window following the Console prompt which looks like this :


Type this in the Console prompt and then press "Enter" :

_$ (setq a "Test")

Now type this and again press "Enter" :

_$ a

Your Console window should look like this :

Visual LISP Console window with code

To view the value of a variable at the AutoCAD Command prompt, you must precede the variable name with an exclamation mark. ( ! ) In VLISP, you simply type the variable name.

Unlike the AutoCAD Command window, where pressing SPACEBAR causes expression evaluation, text input at the VLISP Console prompt is not processed until you press ENTER. This permits you to do the following in the Console window:

  • Continue an AutoLISP expression on a new line. To continue entering an expression on a new line, press CTRL +ENTER at the point you want to continue.
  • Input more than one expression before pressing ENTER. VLISP evaluates each expression before returning a value to the Console window.
  • If you select text in the Console window (for example, the result of a previous command or a previously entered expression), then press ENTER, VLISP copies the selected text at the Console prompt.

The VLISP Console window and the AutoCAD Command window differ in the way they process the SPACEBAR and TAB keys. In the VLISP Console window, a space plays no special role and serves only as a separator. In the AutoCAD Command window, pressing the SPACEBAR outside an expression causes AutoCAD to process the text immediately, as if you had pressed ENTER.

Using the Console Window History

You can retrieve text you previously entered in the Console window by pressing TAB while at the Console prompt. Each time you press TAB, the previously entered text replaces the text at the Console prompt. You can repeatedly press TAB until you cycle through all the text entered at the Console prompt during your VLISP session. After you’ve scrolled to the first entered line, VLISP starts again by retrieving the last command entered in the Console window, and the cycle repeats. Press SHIFT + TAB to scroll the input history in the opposite direction. For example, assume you entered the following commands at the Console prompt:

(setq origin (getpoint "\nOrigin of inyn sign: "))
(setq radius (getdist "\nRadius of inyn sign: " origin))
(setq half-r (/ radius 2))
(setq origin-x (car origin))
(command "_.CIRCLE" origin radius)

To retrieve commands entered in the Console window :

  1. Press TAB once. VLISP retrieves the last command entered and places it at the Console prompt :

    _$ (command "_.CIRCLE" origin radius)
  2. Press TAB again. The following command displays at the Console prompt :

    _$ (setq origin-x (car origin))
  3. Press TAB again. VLISP displays the following command :

    _$ (setq half-r (/ radius 2))
  4. Now press SHIFT+ TAB . VLISP reverses direction and retrieves the command you entered after the previous command :

    _$ (setq origin-x (car origin))
  5. Press SHIFT+ TAB again. VLISP displays the following command :

    _$ (command "_.CIRCLE" origin radius)

    This was the last command you entered at the Console prompt.

  6. Press SHIFT+ TAB again. Because the previous command retrieved was the last command you entered during this VLISP session, VLISP starts again by command you entered in the Console window :

    _$ (setq origin (getpoint "\nOrigin of inyn sign: "))

Note : If you enter the same expression more than once, it appears only once as you cycle through the Console window input history. You can perform an associative search in the input history to retrieve a specific command that you previously entered. To perform an associative search of the Console input history :

  1. Enter the text you want to locate. For example, enter (command at the Console prompt :

    _$ (command
  2. Press TAB. VLISP searches for the last text you entered that began with (command :

    _$ (command "_.CIRCLE" origin radius)

    If VLISP does not find a match, it does nothing (except possibly emit a beep). Press SHIFT+ TAB to reverse the direction of the associative search and find progressively less-recent inputs.

Interrupting Commands and Clearing the Console Input Area

To interrupt a command entered in the Console window, press SHIFT + ESC. For example, if you enter an invalid function call like the following:

_$ ((setq origin-x (car origin)

Pressing SHIFT + ESC interrupts the command, and VLISP displays an "input discarded" message like the following :

((_> ; <input discarded>

If you type text at the Console prompt, but do not press <Enter>, then pressing ESC clears the text you typed. If you press SHIFT + ESC, VLISP leaves the text you entered in the Console window but displays a new prompt without evaluating the text.

If you type part of a command at the Console prompt, but activate the AutoCAD window before pressing <Enter>, VLISP displays a new prompt when you next activate the VLISP window. The text you typed is visible in the Console window history, so you can copy and paste it, but you cannot retrieve the text by pressing TAB , because it was not added to the Console history buffer.

When you're ready, let's continue to Part 2.