ZYSNOR

Glossary · CAD and BIM

What is AutoLISP? Meaning, Example and How It Works

By , Founder of ZYSNOR · Updated · Checked · 5 min read

In simple words

AutoLISP is the programming language built into AutoCAD for adding your own commands and automating repeated drawing work. A short AutoLISP file can draw, count, measure or change objects in seconds instead of minutes. CAD drafters, CAD managers and engineers write or load AutoLISP routines to save time on repeated work.

It is based on the LISP language and was added to AutoCAD in the mid-1980s. Programs are plain-text .lsp files that can be compiled to .fas files or packaged as .vlx files. Full AutoCAD supports it, and AutoCAD LT for Windows added AutoLISP and dialog boxes (DCL) in its 2024 release.

Why it matters

Many drawing tasks repeat on every project, such as adding up lengths, counting items or renaming layers. A routine does the task the same way every time, which saves time and avoids typing errors. Since the 2024 release, AutoCAD LT for Windows also runs AutoLISP and DCL, so the same routines reach more users.

How it works

A function defined with defun whose name starts with c: becomes a command you can type, just like LINE or COPY. Inside it, AutoLISP can ask for points and objects (getpoint, ssget), read an object's data (entget), do the arithmetic and change or create objects. Code is written in any text editor; Autodesk's extension for Visual Studio Code adds editing and debugging, and the older Visual LISP editor is also available.

Five steps: write a .lsp file, load it, type the command, run it, see the result
A defun named c:NAME becomes a command you can type.

Worked example: total length of selected lines

This routine adds up the lengths of the lines you select and prints the total.

(defun c:ZYLEN (/ ss i e total)
  (setq ss (ssget '((0 . "LINE"))) total 0.0 i 0)
  (if ss
    (repeat (sslength ss)
      (setq e (entget (ssname ss i))
            total (+ total (distance (cdr (assoc 10 e)) (cdr (assoc 11 e))))
            i (1+ i))))
  (princ (strcat "\nTotal length: " (rtos total 2 2)))
  (princ))

How it reads: ssget lets you select objects but keeps only lines; for each line, entget reads its data, group 10 is the start point and group 11 the end point, and distance measures between them. rtos turns the total into text with 2 decimal places.

Bar chart of three lines of 4.00, 3.50 and 4.00 m and a total of 11.50 m
The routine adds 4.00 + 3.50 + 4.00 and prints 11.50.

Run on three wall lines of 4.00 m, 3.50 m and 4.00 m, the command line shows "Total length: 11.50" because 4.00 + 3.50 + 4.00 = 11.50. In a drawing set in metres that is 11.50 m of wall line.

Step by step: using a routine

  1. Save the code as a plain-text file, for example zylen.lsp.
  2. In AutoCAD, run APPLOAD, select the file and click Load (add it to the Startup Suite to load it in every session).
  3. Type the command name, here ZYLEN, and press Enter.
  4. Answer the prompts, here by selecting lines, and read the result.

Types

  • .lsp: plain-text source code, readable and editable.
  • .fas: a compiled form of one program.
  • .vlx: a packaged application that can hold several files.
Table of .lsp, .fas, .vlx, acaddoc.lsp and .dcl files
Source files can be read and checked; compiled files cannot.

AutoCAD and AutoCAD LT

Most AutoLISP code runs in both. In LT, functions that create 3D solids or surfaces, link to other applications or rely on ObjectARX and .NET add-ons do not work, and compiling to .fas or .vlx needs full AutoCAD for Windows, although LT can load compiled files.

Common mistakes

  • Loading routines from unknown sources: a routine runs with your rights and can change drawings or settings. Keep the secure-load setting on and use trusted folders.
  • No error handler, so a cancelled command leaves system variables (such as object snaps) changed.
  • Command names that clash with another routine or a built-in alias.
  • Forgetting the final (princ), so the last returned value is echoed on the command line.
  • Assuming drawing units: the same routine gives 11500 in a drawing set in millimetres.

Related terms

Frequently asked questions

How do I load a LISP file?

Use APPLOAD, or add it to the Startup Suite to load it every time.

Is AutoLISP safe?

A LISP runs with your AutoCAD rights. Use files only from sources you trust, and keep SECURELOAD on.

What are .fas and .vlx files?

Compiled forms of AutoLISP programs; .vlx can package several files together.

Sources

← All glossary terms