If you’re looking for a complete, beginner-friendly guide to AutoLISP for AutoCAD, this article explains what AutoLISP is, why and when to use it, how to write/load/edit AutoLISP routines, practical step-by-step examples, alternative automation methods, common errors and fixes, plus productivity tips.
What is AutoLISP?
AutoLISP is a dialect of the LISP Programming language built into AutoCAD (and BricsCAD in a compatible form). It lets you create custom commands, automate repetitive tasks, and extend AutoCAD’s behavior without external compilers. AutoLISP files use the .lsp extension and can be loaded into a drawing session to add new commands or functions.
Why use AutoLISP?
- Automate repetitive drafting tasks to save time and reduce errors.
- Create custom commands tailored to your workflow (e.g., batch dimensioning, custom labeling).
- Integrate drawing logic specific to your discipline (civil, architectural, MEP, structural).
- Combine with AutoCAD commands using the built-in (command) function for stable interaction.
- Easy to learn for beginners compared with compiled APIs like ObjectARX or .NET.
When and where to use AutoLISP
Use AutoLISP when you need to:
- Reuse complex command sequences repeatedly.
- Generate geometry based on rules or data.
- Standardize annotations, blocks, or layer setup across projects.
- Create small utilities quickly without building a full plugin.
Avoid AutoLISP when you need:
- High-performance compiled code for very large datasets (use .NET/ObjectARX).
- Deep integration with modern UI toolkits (use AutoCAD .NET/VL.NET).
Basic AutoLISP concepts (simple explanations)
S-expressions and functions
AutoLISP syntax is based on S-expressions. A function call looks like:
(command “LINE” pt1 pt2 “”)
Common functions
- (defun c:Name () …) — defines a command available directly in the AutoCAD command line as “Name”.
- (setq var value) — sets a variable.
- (getpoint), (getint), (getstring) — user input functions.
- (load “file”) — loads an external .lsp file.
Return and silent output
- (princ) is used to suppress unwanted output and return quietly.
Step-by-step: Create, load and run a simple AutoLISP command
Below is a short example that creates a rectangle by asking for width and height and drawing a polyline rectangle. Save this as rectangle.lsp.
Example code:
lisp
(defun c:RECTSZ ( / p w h pts)
(setq p (getpoint “\nPick base point: “))
(if (and p
(setq w (getdist p “\nEnter width: “))
(setq h (getdist p “\nEnter height: “)))
(progn
(setq pts (list p
(polar p 0 w)
(polar p 0 w) ; placeholder, replaced below
nil))
(setq pts (list
p
(polar p 0 w)
(polar p (/ pi 2) h)
(polar p pi w)))
(command “_.PLINE” (nth 0 pts) (nth 1 pts) (nth 2 pts) (nth 3 pts) “C”)
(princ “\nRectangle created.”)
)
(princ “\nOperation canceled.”)
)
(princ)
)
How to use:
- Save the code in a file named rectangle.lsp.
- In AutoCAD, open the APPLOAD command and load rectangle.lsp, or type (load “C:/path/rectangle.lsp”) at the command line.
- Type RECTSZ on the AutoCAD command line.
- Pick the base point, then enter width and height.
How to edit AutoLISP
Tools
- VLIDE (Visual LISP Editor): built into AutoCAD — ideal for editing, debugging, and stepping through code.
- Notepad / VS Code: lightweight editing; use an extension for LISP syntax highlighting if available.
Editing steps in VLIDE
- Launch VLIDE (type VLIDE in AutoCAD).
- Open your .lsp file or create a new one.
- Use breakpoints and the debugger to step through code.
- Save and reload using Load Active Edit or use (load “path/filename.lsp”) in AutoCAD.
Startup loading
- Add frequently used routines to acaddoc.lsp, acad.lsp, or use the Startup Suite in APPLOAD to automatically load your .lsp files on startup.
Advanced topics (brief)
- .fas/.vlx: compiled/protected versions of LISP for distribution (.fas, .vlx).
- *Visual LISP functions (VL-): provide extended capabilities (file I/O, ActiveX/VLA functions). Use vla-**/vla-get/vla-put for COM automation.
- Working with entities: use entget, entmod, entmake for reading and creating entities at the DXF group code level.
Alternative automation methods
AutoCAD Script Files (.scr)
- Pros: Simple, recorded command sequences; good for linear automation.
- Cons: Limited interactivity and conditional logic.
Action Recorder
- Pros: Record repetitive manual actions into a macro; easy for non-programmers.
- Cons: Less flexible than AutoLISP; harder to edit logic.
AutoCAD .NET API (C# / VB.NET)
- Pros: Strong performance, modern IDE, better UI integration.
- Cons: Requires compilation and programming skills.
dynamic blocks, Tool Palettes, and Macros
- Useful for standardization and quick insertion of common content without custom coding.
Common errors and how to fix them
Error: “Undefined function”
Fix: Ensure your function is defined with (defun c:Name …) and that the .lsp file is loaded. Check naming and spelling.Error: “Bad argument type”
Fix: Verify the types returned by prompts ((getpoint) returns a point list, (getint) returns an integer). Convert or validate inputs before use.Error: “Unbalanced parenthesis” or “Read error”
Fix: Check parentheses. Use VLIDE to pinpoint line numbers and syntax errors.Error: “Can’t find file” or “No such file or directory” for (load)
Fix: Use full path or place file in a folder listed in AutoCAD’s support file search path.Error: “Attempt to call a non-function”
Fix: Make sure the symbol you call is bound to a function; avoid naming collisions with variables and functions.Problem: Changes not taking effect after editing .lsp
Fix: Reload the file using (load “filename”) or re-start AutoCAD. In VLIDE use “Load Active Edit”.
Practical tips and best practices
- Use meaningful names for functions and variables; prefix company initials to avoid collisions (e.g., ABC_DimTag).
- Comment your code extensively with semicolons ; to explain logic.
- Use version control or backups for important .lsp files.
- Keep small, single-purpose routines — easier to test and reuse.
- Validate user input and handle cancel operations gracefully.
- Use (princ) at the end of a command to avoid printing unwanted LISP return values.
- Test on copies of drawings to avoid accidental data loss.
- Document required layers, linetypes, and blocks your routines depend on, or create them programmatically.
Examples and mini-tutorial ideas
- Batch rename layers based on a pattern.
- Place a block from a folder and set its attributes automatically.
- Create a standardized title block insertion routine that fills attributes from a CSV file.
- Generate a column grid based on user-entered spacing and number of bays.
Each example can be developed incrementally: prototype with command sequences, then convert to a robust AutoLISP routine with input validation and error handling.
FAQ
How do I make AutoLISP load automatically every time AutoCAD starts?
Use the Startup Suite in the APPLOAD dialog, or place your routine in acad.lsp / acaddoc.lsp, or add a (load “path/yourfile.lsp”) call in a startup script located in AutoCAD’s support path.
Can AutoLISP manipulate new AutoCAD features like dynamic blocks or sheet sets?
Yes, AutoLISP (especially with Visual LISP/ActiveX calls via vla-*) can interact with many object model features. For very new or complex features, the .NET API may offer better support.
Is AutoLISP still supported in the latest AutoCAD versions?
AutoLISP is still supported in most AutoCAD releases. Some modern features are better handled via .NET APIs, but AutoLISP remains a valid tool for rapid customization.
How do I secure or hide my AutoLISP source code?
Compile to .fas or .vlx formats using the Visual LISP environment or distribution tools to obfuscate source code for distribution.
Where should I store AutoLISP files for team access?
Use a shared network folder included in AutoCAD’s Support File Search Path or deploy via a company standard folder and configure each workstation to load from that location at startup.
How can I debug a routine that behaves differently on another machine?
Check AutoCAD version differences, support paths, missing blocks/layers, and system variables. Use VLIDE debugging, log intermediate values, and ensure all external references are present.
What are the best resources to learn AutoLISP?
Use AutoCAD’s Visual LISP help, online tutorials, community forums, and sample routines. Practice by converting small manual tasks into AutoLISP commands.
