Last updated July 28, 2026
Purging a layer only works if the layer is empty, and finding the last few objects sitting on a layer you want rid of can take longer than the rest of the cleanup put together. They are frozen, or off, or in a layout you forgot about, or inside a block.
Delete Layer skips the hunt. Point at any object on the layer you want gone, and it erases every object on that layer and purges the layer definition. There is a second command that does the same for several layers in one pass. Both are by Mark Thomas.
What it does in practice
You do not type a layer name. You pick an object, and the routine reads the layer off that object — which is faster and removes the chance of a typo emptying the wrong layer.
It then collects every object on that layer across the whole drawing, not just the visible ones, and deletes them one at a time before purging the layer. Because the search is database-wide, objects on frozen or switched-off layers are included, and so is anything in a layout. That is the behaviour that makes it useful — those are exactly the objects that were stopping the purge.
It sets layer 0 current before it starts, since you cannot purge the current layer. Note that it does not put your original current layer back afterwards, so you will find yourself on layer 0 when it finishes.
A layer holding exactly one object is not cleared
There is an off-by-one in the code worth knowing about, because the symptom is confusing rather than dramatic.
The routine counts the objects it found, then checks that the count is greater than zero before starting to delete — but the number it checks has already had one subtracted from it, because it is being used as a list position rather than a count. On a layer with one object that adjusted number is zero, the check fails, and nothing is deleted. The purge then does nothing either, because the layer is still in use.
So the routine works on layers with two or more objects and quietly does nothing on a layer with exactly one. If a layer refuses to go, that is why: erase the single object by hand and purge normally. The fix in the code is a single character — the comparison needs to allow zero as well.
Command reference
- DEL-LAYER — erases everything on one selected layer and purges it.
- MDEL-LAYER — the same for multiple layers in one run.
Note the hyphens. Both names contain one, which is legal in a command name but easy to leave out when typing.
How to load it
Unzip Del-layer.zip and load del-layer.lsp with APPLOAD. Both commands come from the one file. Given what it does, load it when you need it rather than leaving it in the Startup Suite. Our AutoLISP guide covers loading.
Step-by-step usage
- Work on a copy, or at least save first. This deletes objects you cannot see, which makes checking the result harder than usual.
- Type DEL-LAYER.
- At “Select layer to remove:” click any object on the layer you want gone.
- Everything on that layer is erased and the layer is purged. You are left on layer 0.
- If the layer is still listed, check whether it held exactly one object — see above.
Objects are removed with a low-level delete rather than the ERASE command, so do not rely on a single U to bring them back. Working on a copy is the sensible protection.
Compatibility notes
The file carries no date. It uses selection sets, entity access and the PURGE command, none of which has changed, so it is a reasonable bet on a current release — written-for rather than tested-on, as always.
Plain AutoLISP with no dialog boxes and no Express Tools calls, so nothing requires the full product; LT users on LT 2024 or later, the release that brought AutoLISP to LT, should be able to run it. See what runs on AutoCAD LT.
Download
| Name: | Delete Layer |
| Description: | A great routine for when you need to clean a drawing up and delete layers without complications of still having entities on the layer that you can’t find. |
| Type: | AutoCAD AutoLISP Routine |
| Author: | Mark Thomas |
| File Size: | 2 Kb |
| Cost: | Free |
| Worked on: | AutoCAD |
| Download File: | Del-layer.zip |
Related routines
- Delete All Text — the same idea aimed at an object type rather than a layer.
- UPDBLOCK — move block contents onto a sensible layer before you start deleting.
- LLP Suite — a large set of layer management commands.