LAYERPILOT watches every command you start and silently switches the current layer to whichever layer that command’s output belongs on. Start TEXT and you land on the TEXT layer; start DIMLINEAR and you land on DIMENSIONS; finish the command and your original layer comes straight back.
What LayerPilot does
You never touch the layer dropdown again, and drawings stop accumulating text on the dimension layer.
Beyond the layer itself, it can force object properties — colour, linetype, lineweight, transparency — back to ByLayer for the duration of the command, so a stray “current colour = red” setting can no longer contaminate new geometry.
It also handles external references. Attach an xref and the inserted INSERT entity is moved onto a layer named after the xref itself, such as XREF-SITEPLAN, keeping xrefs independently controllable.
Three commands: LAYERPILOTON starts it, LAYERPILOTOFF stops it, and LAYERPILOTECHO toggles command-name echoing — which is how you discover the exact name of a command you want to add to the table.
How to use it
- Load the routine with
APPLOAD, or put it on your support file search path. - Edit the SETTINGS block to map commands to your own layer names. Nothing below that block needs editing.
- Type
LAYERPILOTON. - To add a command you are unsure of, run
LAYERPILOTECHO, start the command, and read the name it reports. - It enables itself automatically on every drawing open, by appending to
S::STARTUP.
How it works
The routine is driven entirely by reactors — event callbacks AutoCAD fires as commands begin and end. Two are needed: a command reactor for built-in AutoCAD commands, and a LISP reactor for AutoLISP-defined ones, because a custom command such as C:MYTEXT never reaches the command reactor under its own name.
When a command starts, the routine normalises the reported name, scans the settings table for the first wildcard pattern that matches it, creates the target layer if it does not yet exist, then pushes the current layer and property system variables onto stacks before applying the new ones. When the command ends, is cancelled or fails, it pops those stacks and restores what was saved.
Stacks rather than single variables, because commands nest. A LISP command may internally call LINE, which may be transparently interrupted by ZOOM. Each “will start” pushes and each “ended” pops, so restoration always unwinds in the correct order no matter how deep the nesting goes. A single saved variable would be overwritten by the inner command and you would end up on the wrong layer.
The state variables have to be global. Reactor callbacks are invoked by AutoCAD long after the command that created the reactor has returned, so there is no enclosing function whose local variables they could see. Every one is namespaced with a *LayerPilot:...* prefix so it cannot collide with anything else loaded in the drawing.
Notes and limits
- Configure the SETTINGS block first. The shipped table will not match your office layer names.
- Use LAYERPILOTECHO to find command names. The name AutoCAD reports is not always the one you type.
- It enables itself on drawing open via
S::STARTUP. UseLAYERPILOTOFFif you need it out of the way. - Forcing properties to ByLayer is optional but is the setting that stops a stray current colour contaminating new work.
Download and details
| Name | LayerPilot — switch the current layer automatically to suit each command |
| Download | LayerPilot.lsp — 35.5 KB, plain AutoLISP source. Downloads directly; no zip to unpack. |
| Type | AutoCAD AutoLISP routine |
| Commands | LAYERPILOTECHO, LAYERPILOTOFF, LAYERPILOTON |
| Requires | the ActiveX layer (loaded automatically by the routine with vl-load-com). |
| Source size | 35.5 KB, 828 lines |
| Error handling | Yes — a *error* handler restores every system variable it changed, on cancel as well as on error. |
| Undo | Not needed — this routine only reads the drawing and changes nothing. |
| Compatibility | AutoCAD (any release with AutoLISP), BricsCAD, ZWCAD, GstarCAD, ProgeCAD and other IntelliCAD-based platforms. AutoCAD LT needs a LISP enabler. No .NET, no ObjectARX, no installer. |
| Author | YZ, August 2026 |
| Licence | Free to use, supplied “as is” with no warranty. |
References
- LAYERHARVEST LISP — audit a set of drawings against the standard
- LS LISP — set a layer manually, or create it on the fly
- STARTUPBUILDER LISP — manage what loads automatically
- More free AutoLISP routines on this site
- Wisey’s Steel Shapes — free structural steel section drawing program