βοΈ Lesson 5.13 β Creating Loadable Routines with AutoLISP
Learn how to make your AutoLISP scripts load automatically using startup scripts and autoload techniques.
π What Youβll Learn
By the end of this lesson, youβll be able to:
- Organize your AutoLISP code into separate, reusable files
- Enable AutoCAD to load your code automatically at startup
- Use
autoload
to delay loading until needed - Configure your environment with a startup script
π§ Why It Matters
If you use AutoLISP tools regularly, you donβt want to reload them manually each time you open AutoCAD. By setting up autoloading and startup routines, you can save time, reduce friction, and maintain a clean, modular codebase.
π οΈ Tools Youβll Use
Tool / Function | Purpose |
---|---|
load | Loads an AutoLISP file immediately |
autoload | Delays loading until a specific function is called |
acad.lsp | AutoCAD script that runs at session start |
startup.lsp | Custom file that runs after AutoCAD finishes loading |
APPLOAD | Dialog box to manage startup loading |
π§ Lesson Structure
1οΈβ£ Create a Loadable LISP File
Save your function in a standalone .lsp
file. For example:
π greeting.lsp
(defun c:greet ( / )
(alert "Welcome to your custom AutoCAD workspace!")
(princ)
)
2οΈβ£ Load Manually with load
You can test it manually:
(load "greeting.lsp")
(greet)
π Ensure the .lsp
file is in a support path (Options β Files β Support File Search Path)
3οΈβ£ Use autoload
for On-Demand Loading
Add this to startup.lsp
or acad.lsp
:
(autoload '("greet") "greeting.lsp")
AutoCAD wonβt load the file until greet
is calledβsaving memory and boot time.
4οΈβ£ Add to startup.lsp
for Session Load
The startup.lsp
file runs after AutoCAD fully initializes. You can load multiple routines:
π startup.lsp
(princ "\\nCustom AutoLISP startup script running...")
(load "greeting.lsp")
(load "layer_setup.lsp")
(princ)
Place this file in AutoCADβs Support File Search Path.
β Lesson Checklist
Task | Completed |
---|---|
Created reusable LISP files | β |
Used load to test manually | β |
Applied autoload for performance | β |
Created and used startup.lsp | β |
Added LISP files to Support File Search Path | β |
π Quick Tips
Tip | Why It Helps |
---|---|
Keep routines modular (1 file = 1 tool) | Easier maintenance and reuse |
Use autoload for tools used occasionally | Improves AutoCAD launch performance |
Use APPLOAD to test or manage loaded files | Graphical way to manage LISP files |
Always add (princ) at end of startup scripts | Suppresses unwanted command line output |
π§© Real-World Applications
Use Case | What Loads | Why It Helps |
---|---|---|
Office-wide toolset | Block insertion, layer setup | Reduces need for manual loading |
Developer toolkit | LISP function library | Share common tools across projects |
Custom welcome routine | Greeting, logging, tips | Improves user engagement |
π Files and Resources
File / Resource | Description |
---|---|
greeting.lsp | Simple tool with alert message |
startup.lsp | Sample file to load multiple LISP routines at startup |
autoload_example.lsp | Template showing how to defer load with autoload |
load_order_checklist.docx | Printable checklist to help you organize routine loading |
π Review Table
Function | Description | Example |
---|---|---|
load | Loads a LISP file | (load "file.lsp") |
autoload | Delays load until function is called | (autoload '("func") "file.lsp") |
princ | Ends routine quietly | (princ) |
APPLOAD | GUI for loading apps/scripts | Type APPLOAD in the command line |