RecipesCount and measure
How do I list all layers in an AutoCAD drawing with the number of objects on each?
Type "list every layer with how many objects are on it". cadssistant reads the layer table, tallies every entity in the drawing by its layer in one AutoLISP pass, and replies with a table of layer and count, empty layers included; ask for colour and on/off/frozen state as extra columns. Nothing is modified. From there, "delete the empty ones" runs PURGE for exactly those layers.
Checked 2026-10-30
list every layer with how many objects are on it
Paste it into the palette, or pick it from the recipes inside the chat.
What cadssistant does
- Walks the layer table with tblnext so every layer is listed, including the empty ones.
- Selects every entity with (ssget "_X") and counts them by layer in the same pass.
- Replies with one table: layer and objects (colour and state on request). Layers with zero objects are listed too, which is the list PURGE would remove.
The same task in AutoLISP
(progn
(setq ss (ssget "_X") i 0 tally nil)
(if ss
(repeat (sslength ss)
(setq lay (cdr (assoc 8 (entget (ssname ss i)))) i (1+ i))
(setq tally
(if (assoc lay tally)
(subst (cons lay (1+ (cdr (assoc lay tally)))) (assoc lay tally) tally)
(cons (cons lay 1) tally)))))
(setq def (tblnext "LAYER" T))
(while def
(if (not (assoc (cdr (assoc 2 def)) tally))
(setq tally (cons (cons (cdr (assoc 2 def)) 0) tally)))
(setq def (tblnext "LAYER")))
tally)Counts entities by layer, then adds the layers nothing sits on with a count of 0.
Good to know
- Entities inside block definitions are not counted: a layer used only inside a block shows 0 here, but PURGE will still refuse to remove it.
- Say "model space only" to add (410 . "Model") to the filter and leave the layouts out.
More in count and measure
Command: CADSSISTANT
Works in AutoCAD 2024 and newer on Windows. Free trial, no card, no API key.
Get cadssistant