RecipesEdit in bulk

How do I delete everything on a layer and purge it in AutoCAD?

Type "delete everything on layer TEMP and purge the layer". cadssistant selects the objects on TEMP, erases them with one ERASE command on that filtered selection, runs -PURGE for that layer alone, and replies with how many objects went and whether the layer was removed. Revert in the chat brings all of it back. Objects inside blocks, and anything on a locked layer, stay.

Checked 2026-10-30

What you typeCommand: CADSSISTANT

delete everything on layer TEMP and purge the layer

Paste it into the palette, or pick it from the recipes inside the chat.

What cadssistant does

  1. Selects everything on TEMP with (ssget "_X" '((8 . "TEMP"))) and notes how many that is.
  2. Runs ERASE on that selection in one command, then -PURGE with the Layers option naming TEMP, no confirmation prompt.
  3. Replies with the count and the purge result. If TEMP is the current layer PURGE refuses; it switches to layer 0 first and says so.

The same task in AutoLISP

(progn
  (setq ss (ssget "_X" '((8 . "TEMP"))))
  (if ss (command "_.ERASE" ss ""))
  (if (= (getvar "CLAYER") "TEMP") (setvar "CLAYER" "0"))
  (command "_.-PURGE" "_LA" "TEMP" "_N")
  (if ss (sslength ss) 0))

Erases, makes sure TEMP isn't current, purges it. The layer only goes when nothing references it, block definitions and xrefs included.

Good to know

  • "Delete the layer" alone would leave its objects. LAYDEL does both in one step but also deletes the objects inside block definitions, which this doesn't; say "LAYDEL" if that's what you want.
  • ERASE skips objects on a locked layer silently. Say "unlock it first" and it does.

More in edit in bulk

Command: CADSSISTANT

Works in AutoCAD 2024 and newer on Windows. Free trial, no card, no API key.

Get cadssistant