AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

Using the Visual Lisp Editor (cont)

Right, enough messing about. Let's load some coding. Choose "File" - "New" and then copy and paste this coding into the text editor :

(defun C:SLOT ( )

  (setvar "CMDECHO" 0)
  (setvar "BLIPMODE" 0)
  (setq oldsnap (getvar "OSMODE"))

  (setq diam (getdist "\nSlot Diameter : ")
          lngth (getdist "\nSlot Length : "))

     (setq pt1 (getpoint "\nInsertion point: "))
     (setvar "OSMODE" 0)
     (setq pt2 (polar pt1 0.0 (/ (- lngth diam) 2.0))
             pt3 (polar pt2 (/ pi 2.0) (/ diam 4.0))
             pt4 (polar pt3 pi (- lngth diam))
             pt5 (polar pt4 (* pi 1.5) (/ diam 2.0))
             pt6 (polar pt5 0.0 (- lngth diam)))

     (command "PLINE" pt3 "W" (/ diam 2.0) "" pt4
                       "ARC" pt5 "LINE" pt6 "ARC" "CLOSE")
     (setvar "OSMODE" oldsnap)

The coding should look like this in the text editor :

Before we go any further, let's have a wee chat about the colors.
As soon as you enter text in the VLISP Console or text editor windows, VLISP
attempts to determine if the entered word is a built-in AutoLISP function, a number, a string, or some other language element. VLISP assigns every type of element its own color. This helps you detect missing quotes or misspelled function names. The default color scheme is shown in the following table.

AutoLISP Language Element     Color
Built-in functions and protected symbols Blue
Strings  Magenta
Integers Green
Real numbers  Teal
Comments Magenta, on gray background
Parentheses    Red
Unrecognized items (for example, user variables) Black

You can change the default colors. But, do yourself a favour. Don't!!

Selecting Text

The simplest method to select text is to double-click your left mouse button. The amount of text selected depends on the location of your cursor.

  • If the cursor immediately precedes an open parenthesis, VLISP selects all the following text up to the matching close parenthesis.

  • If the cursor immediately follows a close parenthesis, VLISP selects all preceding text up to the matching open parenthesis.

  • If the cursor immediately precedes or follows a word, or is within a word, VLISP selects that word.

Hint : Would you like help on any AutoLisp function? Double-click on the function name to select it, and then select the "Help" toolbar button. Help for the specific function will be displayed.

To load the "Slot" lisp routine, select the "Load active edit window" toolbar button :

This loads your coding into memory. To run the routine, type this at the Console prompt :

_$ (c:slot)

The program should now run, switching over to the AutoCAD screen when required. You can also just run a selection of code if you desire. Select the lines of code you would like to run and choose the "Load selection" toolbar button, and then press "Enter."

Only the lines of code you selected will be run, Great for debugging.

Talking about debugging, Place the cursor in front of the (defun C:SLOT () statement and press "F9". This places a "Breakpoint" into your program. Now run the program again. Execution should stop at the Breakpoint mark. Now press "F8". By continuously pressing "F8" you can "single step" through your whole program :

Let's go one step further. Select the "diam" variable and then select the "Add Watch" toolbar button :

The "Watch" dialog box will appear :

Note how the variable "diam" is listed along with it's present value. Repeat this process for all the other variables until the Watch" dialog looks like this :

Now run the program again, still "single" stepping through. Notice how the values of the variables change as the program proceeds.

O.K. let's liven things up a bit. Select "Ctrl-Shift-F9" to clear all breakpoints. Now select the "Debug" pull down menu and then "Animate". Now run the program again.
Hey, it's running automatically!!! Take note of the variables changing in the "Watch" window as the program does it's thing.

Well that's about it in regards to the Visual Lisp Editor. The editor has a lot more functions than I've shown you here, but these I feel, are some of the more important ones to get you started.

The AutoLisp/Visual Lisp/VBA Resource Website

Copyright 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website