How to Write Lisp Routines in AutoCADby Wolfram DonatUpdated February 10, 2017
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.
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.
Launch the VLISP text editor by selecting "File", then "New." The text editor enables you to write and save complete LISP programs, or routines.
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.
Save the routine by choosing "Save As..." from the "File" menu, then save the file as "hello.lsp".
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.
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.
Type "hello" (without quotes) at the AutoCAD command prompt. You will immediately see the string "Hello, world" displayed at the prompt.
LISP is a programming language, and the best way to learn any programming language is by practicing its use.
- "Harnessing AutoCAD 2006"; Thomas Stellman & G.V. Krishnan; 2006