AutoLISP is a dialect of the Lisp programming language designed for extending and automating tasks within Autodesk AutoCAD and its derivative products. It provides a command-like syntax that allows users to define custom functions, manipulate drawing entities, and interact with the AutoCAD user interface. First introduced in AutoCAD Release 2.18 in 1986, AutoLISP remains a widely used tool for creating macros, parametric designs, and custom workflows, leveraging a rich set of built-in functions for geometric calculations, file I/O, and database operations.

1 History and Evolution

1.1 Origins and Adoption in AutoCAD

AutoLISP was created by Autodesk to provide a scripting interface for AutoCAD. It was first included in AutoCAD Release 2.18 (1986), allowing users to automate repetitive drafting tasks without leaving the drawing environment. Its Lisp-based syntax appealed to engineers and programmers seeking a flexible, interpretive language for CAD customization.

1.2 Relationship to Common Lisp and XLISP

AutoLISP is derived from XLISP, a small Lisp interpreter written by David Betz. While it shares core Lisp concepts like s-expressions and functional evaluation, it was tailored for AutoCAD’s entity database and command system. It lacks full Common Lisp features such as lexical scoping, packages, and advanced data structures, but retains a minimal, practical subset.

1.3 Subsequent Versions (AutoLISP for Visual LISP)

In AutoCAD 2000, Autodesk introduced Visual LISP (VLISP), an integrated development environment (IDE) that extended AutoLISP with features like an interactive debugger, compiler, and ActiveX/COM support through functions prefixed with vl-. VLISP also added object-oriented programming capabilities via the vla- family of functions. The language is often referred to collectively as AutoLISP/Visual LISP.

1.4 Influence on Modern AutoCAD APIs

AutoLISP paved the way for later API offerings such as VBA, .NET, and ObjectARX. While newer interfaces are more powerful, AutoLISP remains relevant due to its low learning curve, direct access to drawing primitives, and extensive legacy codebase. It continues to be supported in current AutoCAD versions (including AutoCAD 2025).

2 Syntax and Basic Concepts

2.1 S-Expressions and Evaluation Model

AutoLISP code is written as s-expressions (symbolic expressions) enclosed in parentheses. The first element of an expression is a function or operator, followed by its arguments. Evaluation proceeds from the innermost parentheses outward. For example, (+ 2 3) evaluates to 5. The quote special form (') prevents evaluation, allowing lists to be treated as data.

2.2 Data Types (Numbers, Strings, Lists, Symbols, File Descriptors)

AutoLISP supports several primitive types:

  • Numbers: integers (e.g., 42) and reals (e.g., 3.14).
  • Strings: sequences of characters enclosed in double quotes (e.g., "Hello").
  • Lists: ordered collections of elements, e.g., (1 2 3).
  • Symbols: names that evaluate to their bound value (e.g., myVar).
  • File descriptors: objects obtained from (open ...).

Additional types include entity names, selection sets, and VLA-objects.

2.3 Variable Binding and Symbol Table

Variables are created by binding a symbol to a value using setq. For example, (setq radius 5.0). Symbols are stored in the AutoCAD symbol table, which is global by default. AutoLISP does not enforce strict scoping; variables defined with setq at the top level are accessible anywhere unless localised.

2.4 User-Defined Functions (defun)

Functions are defined using defun. Basic syntax: (defun function-name (arguments) ... body ...). Example:

(defun square (x) (* x x))

2.4.1 Required and Optional Arguments

Arguments listed in defun are required. Optional arguments can be defined using the / separator. For instance, (defun greet (name / greeting) ...). Default values are not natively supported but can be simulated with cond or if checks.

2.4.2 Local and Global Variables (C:LispFunction)

Variables after the / in a defun argument list are local to that function. Global variables are created by setq outside of any function. To make a function invocable as an AutoCAD command, prefix its name with C: – e.g., (defun C:MYCMD () ...). This allows the user to type MYCMD at the AutoCAD command prompt.

3 Built-in Functions and Libraries

3.1 Utility Functions (Arithmetic, String, List)

AutoLISP provides a range of utility functions:

  • Arithmetic: +, -, *, /, abs, sqrt, sin, cos, atan, expt, etc.
  • String: strcat, substr, strlen, itoa, atof, ascii, chr.
  • List: car, cdr, cons, list, append, reverse, length, assoc, subst, mapcar, apply.

3.2 Entity Access and Modification (entget, entmod, entmake)

These are the core functions for manipulating AutoCAD drawing entities:

  • entget returns an association list (list of DXF code-value pairs) representing an entity.
  • entmod updates an entity in the drawing database using a modified association list.
  • entmake creates a new entity directly from a DXF association list.

3.2.1 Entity Association Lists and DXF Codes

DXF codes are integer keys that define entity properties. For example, code 0 is the entity type, 10 is the insertion point (for lines, points), 40 is radius, and 62 is color. An entity list might look like:

((-1 . <Entity name: ...>) (0 . "LINE") (10 0.0 0.0 0.0) (11 5.0 5.0 0.0) (210 0.0 0.0 1.0))

3.2.2 Selection Set Operations (ssget, ssadd)

ssget prompts the user or uses filters (DXF groups) to create a selection set. ssadd and ssdel add or remove entities from a set. sslength returns the count, and ssname retrieves an entity name by index. Filtered selection, e.g., (ssget "X" '((0 . "CIRCLE") (62 . 1))), selects all red circles.

3.3 Command Execution (command, vl-cmdf)

The command function emulates typing at the AutoCAD command line. Example: (command "LINE" '(0 0) '(10 10) ""). vl-cmdf is similar but supports ActiveX objects and returns immediately without waiting for command completion.

3.4 File and Input/Output (open, read-line, write-line)

File operations use open with modes "r", "w", or "a". Functions like read-line, write-line, read-char, and write-char handle text I/O. Example:

(setq f (open "data.txt" "r"))
(setq line (read-line f))
(close f)

3.5 Error Handling (if, cond, *error*)

AutoLISP supports conditional branching with if and cond. A global error handler can be defined by setting the *error* symbol to a function, which is called when an error occurs. Example:

(defun *error* (msg)
  (princ (strcat "\nError: " msg))
  (princ))

4 Programming Paradigms and Best Practices

4.1 Recursion vs. Iteration (while, repeat)

AutoLISP lacks for loops; iteration is done with while (test condition) and repeat (fixed count). Recursion is possible but limited by stack depth. Example of while:

(setq i 0)
(while (< i 10)
  (princ i)
  (setq i (1+ i)))

4.2 Modular Code Organization

Code should be organized into small, single-purpose functions. Use defun with local variables to avoid side effects. Separate files can be loaded with load or autoload functions.

4.3 Performance Considerations

Entity manipulation (especially entmod) is slower than using entmake. Minimizing calls to command and using direct DXF changes improves speed. For loops, prefer repeat over while when the count is known.

4.4 Debugging Techniques (print, princ, Visual LISP IDE)

Basic debugging uses princ or print to output values to the command console. The Visual LISP IDE (available in AutoCAD) provides breakpoints, watch windows, and a stack trace, greatly simplifying error detection.

5 Integration with AutoCAD

5.1 Autoloading and Startup

AutoLISP files (*.lsp, *.fas, *.vlx) can be loaded automatically at AutoCAD startup through the acaddoc.lsp file, the Startup Suite (in Options), or by using the APPLOAD dialog. The autoload function registers functions that load only when first called.

5.2 Reaction and Event-Driven Programming (vlr-*)

Visual LISP provides reactors (vlr-* functions) that respond to AutoCAD events, such as drawing opening, entity modification, or command start. Example: (vlr-editor-reactor nil '((:vlr-commandWillStart . my-handler))).

5.3 Dialog Control Language (DCL) for User Interfaces

AutoLISP can create modal dialog boxes using Dialog Control Language (DCL) files. DCL defines the layout, and AutoLISP loads and manages the dialog with functions like load_dialog, new_dialog, action_tile, and done_dialog. Controls include edit boxes, lists, sliders, and buttons.

5.4 Limitations and Compatibility (vs. VBA, .NET, ObjectARX)

AutoLISP is slower and less capable than .NET or ObjectARX for complex operations. It lacks true multi-threading, advanced GUI, and direct Windows API access. VBA (now deprecated) offered stronger object-oriented features. However, AutoLISP’s simplicity and fast prototyping make it ideal for small automation tasks. Compatibility across AutoCAD versions is high due to backward compatibility.

6 Applications and Examples

6.1 Automated Drafting Utilities

Common utilities include automatic layer creation, batch layer renaming, line-type loading, and text styling. For example, a routine that inserts a title block with correct attributes.

6.2 Parametric Part Generation

AutoLISP can generate families of parts (e.g., bolts, springs) based on user input for dimensions. Functions compute geometry and call entmake to draw the part, allowing rapid design variations.

6.3 Batch Processing and Data Extraction

Scripts can iterate over multiple drawing files, extracting properties (block counts, area) to a text file or spreadsheet. vl-directory-files and open are used for file I/O.

6.4 Custom Dimensioning and Annotation Tools

Users create commands that modify dimension styles, add custom tolerances, or place leader notes with formula-derived text, enhancing standard AutoCAD dimensioning.

7 Community and Resources

7.1 Online Forums and Tutorials

Active communities exist on Autodesk Forums, theswamp.org, and Reddit r/AutoLISP. Tutorials are available on YouTube, CADalyst, and AfraLISP.

7.2 Published References (Books, Autodesk Documentation)

Key books include *AutoLISP Programming: Principles and Techniques* by Robert P. S. King and *AutoCAD 2023 for the Interior Designer*’s AutoLISP chapters. Official Autodesk documentation provides the complete function reference (still updated).

7.3 Third-Party Libraries and Open-Source Projects

Libraries like “AutoLISP++” by James Maeding and “Lee Mac’s AutoLISP Functions” offer reusable utilities. GitHub hosts many open-source projects, such as VLAX-* wrappers.

8 Future Outlook

8.1 Continued Use in Legacy Systems

Thousands of firms still rely on custom AutoLISP applications developed over decades. Because AutoCAD continues to support AutoLISP, these systems remain viable without rewriting.

8.2 Migration Paths to Modern Languages

For enhanced performance and maintainability, developers may migrate to C# with .NET or to Python (via pyautocad). Autodesk provides tools and documentation for translating AutoLISP logic to these languages.

8.3 Role in the Broader CAD Automation Ecosystem

AutoLISP remains the entry point for many CAD users into programming. Its low barrier to entry ensures that it will continue to be taught in training courses and used for quick macros, coexisting alongside more advanced APIs in mixed environments.