CADEx

How to Write Your First AutoLISP Routine

AutoCADCivil 3D8 min
Short answer

To write your first AutoLISP routine, open Notepad, paste (defun C:HELLO () (princ "Hello CAD")(princ)), save as hello.lsp, then APPLOAD it in AutoCAD and type HELLO. That five-line file is a complete, working LISP routine.

Steps

1

Open a text editor

Notepad, Notepad++, or VS Code (with the AutoCAD AutoLISP extension) all work. Avoid Word — it injects formatting that breaks AutoLISP parsing.

2

Write the routine

Paste: (defun C:HELLO ( / ) (princ "\nHello from your first LISP routine!") (princ) ) The C: makes HELLO a command. The ( / ) declares no arguments and no local variables. (princ) at the end suppresses nil output.

3

Save the file

Save As → choose 'All Files' so the .txt extension isn't appended. Name it hello.lsp and save somewhere on your AutoCAD support path (or any trusted folder).

4

Load the file

In AutoCAD, type APPLOAD. Browse to hello.lsp. Click Load. The command line says 'Successfully loaded.'

5

Run your command

Type HELLO at the command line and press Enter. You should see your message print.

6

Extend it

Try replacing the body with (command "_LINE" "0,0" "10,10" "") to draw a line, or (entget (car (entsel))) to print the DXF data for any entity you click. The AutoLISP Reference (F1 → Developer Documentation) lists every function.

Frequently asked questions

AutoCAD says 'Unknown command HELLO'. What did I do wrong?

Three things to check: (1) the file actually loaded — APPLOAD → Loaded Applications; (2) the function is defined as C:HELLO not just HELLO; (3) you saved as hello.lsp not hello.lsp.txt — show file extensions in Explorer to confirm.

What does ( / ) mean?

Everything before / is positional arguments; everything after is local variables. ( / x y ) declares no arguments and two locals x and y. Locals shadow globals while the function runs and are released after.

Why two (princ)?

The first is your message. The second, with no arguments, returns nothing visibly — without it AutoLISP would echo the return value of the last expression to the command line, which looks ugly.

How do I read user input?

(getstring "Enter your name: ") or (getreal "Enter a number: ") or (getpoint "Pick a point: "). The result is stored in a variable: (setq name (getstring "Name: ")).

Where can I go next?

Read the AutoLISP Reference (F1 → AutoLISP), Lee Mac's tutorials, and AfraLISP's introductory pages. Pick up George Omura's book if you want a structured path.

Related guides

How to Load a LISP Routine in AutoCAD

Three reliable ways to load .lsp, .fas, and .vlx files into AutoCAD, plus how to add them to the Startup Suite so you never reload again.

What Is AutoLISP and Why CAD Pros Still Use It

AutoLISP explained from scratch — what it is, why it's still relevant 40 years later, and when to choose it over .NET.

Browse listings

AutoCAD LISP Routines

Hundreds of verified AutoLISP and Visual LISP routines for AutoCAD: .lsp source, compiled .fas, and bundled .vlx applications. Loaded with APPLOAD, version-friendly, malware-scanned.

Related terms

AutoLISP

Autodesk's dialect of LISP, built into AutoCAD since 1986, used to write custom commands and automate drawings.

LISP routine

A self-contained AutoLISP program that adds a command or behaviour to AutoCAD — usually one .lsp/.fas file.

APPLOAD

The AutoCAD command that opens a dialog for loading .lsp, .fas, .vlx, .arx, or .dll files into the current session.