AutoLISP
About AutoLISP
LISP is an acronym for LISt Processing, a simple, yet deceptively powerful computer language. It was developed in the 1960's and was first used to control powerful telescopes for astronomy. Not only is this useful for astronomy, it becomes a very sensible choice for Computer Aided Design (CAD) where we are dealing with the placement of entities in drawings at very tightly defined coordinate positions. As an example, it is possible to use lisp to read a line of text in a file describing the x, y and z coordinates of a point in space and then use Lisp to go there. Lisp can interpret the information, store the position of the point in space and other commands can then be called to create useful geometry.
AutoLISP AutoLISP is Autodesk's implementation of the lisp programming language. The major advantage of using AutoLISP in your AutoCAD or IntelliCAD drawings is that it enables the creation of new commands. You can then call that command to perform special functions which are not available in the normal CAD drawing environment.
AutoLISP in action
Here is an example of AutoLISP in action. In this example, we have used AutoLISP in the IntelliCAD environment to import a data file from GPS equipment and have been able to plot trees in and around a wetland. In addition we have captured some information about trunk diameter, condition etc. and assigned this information carried in attributes with the tree symbol.
Another example of the use of AutoLISP:
We have used AutoLISP to create a new command which, when implemented, reads a huge file which contained the XYZ coordinates of light poles in a local council area. LISP then produced a drawing showing a point at every position and XREFERENCED a cadastral drawing showing the council boundaries. This enabled council to make sure that they were only paying for lighting in their area.
AutoLISP on the net
Many sample AutoLISP programs are available on the Internet. The instructions below provide some guidance on testing them out.
Testing an unfamiliar AutoLISP program (simple approach)
Copy the AutoLISP file to the directory in which your drawings normally reside. If you have never used the AutoLISP program before, start Windows Notepad and open the LISP file to view it. [AutoLISP programs have the .LSP extension.] The LISP program may read like 'gobbledgook', but somewhere in it, usually at the beginning, some instruction on how to use the program may be given. Print out the instruction part of the file. The amount of instruction will vary according to the author.
Operation
Most AutoLISP programs will create a new command when loaded which when executed, will carry out some (new) function. An example is shown below.
**(defun c:chgsc ()
(initget "10 20 50 100 200")
(setq newdwgsc(getkword "What is your scale: "))
(setq #dwgsc (atof newdwgsc))
(command "INSERT" (strcat "1-" newdwgsc) "0,0" "1.0" "1.0" "0.0")
(command "DIMSTYLE" "R" (strcat "1-" newdwgsc)) )
Look at the beginning of the file for a line similar to that marked with the * *.
The part that says c:chgsc indicates that the author has decided to create a new command to start the program CHGSC - short for change scale.
Syntax:
Either upper of lower case will work in AutoLISP, it's not case sensitive. Once the LISP file is loaded a new command is created; in this case CHGSC.
Tip: If the AutoLISP program reads a data file, then make sure that the required data file also resides in the same directory.
Loading the AutoLISP program Any AutoLISP program can be loaded from the command line using the following syntax:
(load "filename")
The brackets are essential.
This syntax will only work if the drawing file and the AutoLISP file are saved in the same folder. If the LISP file was in another folder (directory), you need to type the full path. E.g. To load a LISP file called VERIFY.LSP in a folder called Verify on the C drive, you would type: (load "c:/verify/verify.lsp")
Note the use of the forward slash. This is different to Windows paths used when we are setting the path command in the PREFERENCES dialog box. Once the LISP file has been loaded, you can then type your new command.
Loading AutoLISP programs - Method 2:
Create a folder for all of your AutoLISP programs so that they are all kept in one place. E.g. create a folder called C:/AutoLISP
Load the program with the syntax: (load "C:/AutoLISP/filename.lsp")
Loading AutoLISP programs - Method 3
Edit the file ACAD.LSP (or ICAD.LSP) using Windows Notepad and add the "load" command that you have used above into this file. When AutoCAD or IntelliCAD starts, all these LISP files will be loaded, ready to run.
An example of part of an ICAD.LSP file is shown below.
(defun S::STARTUP() (setvar "CMDECHO" 0) (setvar "MENUECHO" 0) ; 1. Load special lisp functions ;
(load (strcat drive "icad_ase/descad.lsp")) johns mod
(load "c:/icad_ase/descad.lsp")
(load "c:/icad_ase/lines.lsp")
(load "c:/icad_ase/cloud1.lsp")
(load "c:/icad_ase/chgsc.lsp") ; change scale
(load "c:/icad_ase/zc.LSP") ;scales and centers view port (load "c:/icad_ase/pinter.LSP") ;interrogates viewport in paper space ;
(load "c:/icad_ase/land/trees/shadow.LSP") ;applies shadowing
(LOAD "C:/ICAD_ASE/JP.LSP") ; JOIN POLYLINES
(defun S::STARTUP() (setvar "CMDECHO" 0) (setvar "MENUECHO" 0) ; 1. Load special lisp functions
(load "c:/icad_ase/descad.lsp")
(load "c:/icad_ase/lines.lsp")
(load "c:/icad_ase/cloud1.lsp")
(load "c:/icad_ase/chgsc.lsp") ; change scale
(load "c:/icad_ase/zc.LSP") ;scales and centers view port (load "c:/icad_ase/pinter.LSP") ;interrogates viewport in paper space
(load "c:/icad_ase/land/trees/shadow.LSP") ;applies shadowing
(LOAD "C:/ICAD_ASE/JP.LSP") ; JOIN POLYLINES
Error messages
It is not uncommon for there to be errors in LISP files, especially those downloaded free of charge from the Internet.
Copyright
If you do use a program created by someone else, keep that person's copyright notice intact in the file and acknowledge their effort. Under no circumstances should you try and profit financially from the work of others. If you need to safeguard your intellectual property, then programming your application in VBA is a better bet.
AutoLISP support (including .DCL)
IntelliCAD preserves your investment in existing custom applications by supporting the LISP programming language. You can run AutoLISP applications that reference any of the hundreds of AutoCAD commands with little or no modification. What's more, IntelliCAD reads DCL files that contain dialog control language statements.
"I find IntelliCAD to be a very impressive CAD engine. The compatibility with our existing AutoCAD 12 DOS Drawings and LISP created over the years is an absolute plus."
— Richard Nichols, Fagan Engineers