How to Write Lisp Routines in AutoCAD

By Wolfram Donat

AutoCAD, from AutoDesk Software, is one of the most common software programs in use today in the engineering industry. It is used to create blueprints, schematics and other engineering drawings and 3D models. If you use AutoCAD every day, and find there are routines that you would like to automate, AutoCAD offers a way to do this: LISP routines. LISP, the name of which is derived from LISt Processing, is a computer programming language that is interfaced with AutoCAD using VLISP, or Visual LISP. You can use the VLISP interface to write and run LISP routines in AutoCAD.

Step 1

Launch the VLISP window. From the AutoCAD window, in the "Tools" menu, select "AutoLISP" and "Visual LISP Editor." In the VLISP window, you can type LISP commands in the console window.

Step 2

Launch the VLISP text editor by selecting "File", then "New." The text editor enables you to write and save complete LISP programs, or routines.

Step 3

Begin your VLISP routine. To create a "Hello, world" application to work at the AutoCAD command prompt, enter the following code:(defun c:hello () (prompt "Hello, world!")(princ))The first line defines the "Hello, world" function. The rest of the program displays the string at the command prompt.

Step 4

Save the routine by choosing "Save As..." from the "File" menu, then save the file as "hello.lsp".

Step 5

Load the program, and from the "Tools" menu, select "Load Text in Editor." The VLISP window should display a confirmation message. If it displays an error code, fix the listed errors in your code and save and load the code again.

Step 6

Switch to your AutoCAD window. From the "Tools" menu, select "AutoLISP" and "Load." Select the hello.lsp file, and click "Load." The file is now ready to run.

Step 7

Type "hello" (without quotes) at the AutoCAD command prompt. You will immediately see the string "Hello, world" displayed at the prompt.

Tips & Warnings

  • LISP is a programming language, and the best way to learn any programming language is by practicing its use.