RecipesDraw and lay out
How do I renumber block tags in order automatically in AutoCAD?
Type "renumber the DOOR-TAG blocks left to right, top to bottom, starting at D01". cadssistant reads every DOOR-TAG insert and its NUMBER attribute, sorts the inserts by row and then by X, writes the new values into the attributes in one AutoLISP pass, regenerates, and replies with a table of handle, old number and new number. Revert in the chat puts the old numbers back.
Checked 2026-10-30
renumber the DOOR-TAG blocks left to right, top to bottom, starting at D01
Paste it into the palette, or pick it from the recipes inside the chat.
What cadssistant does
- Selects the DOOR-TAG inserts that carry attributes ((66 . 1) in the filter) and reads each one's insertion point and NUMBER attribute.
- Sorts by Y descending (rows), then X ascending within a row, with a row tolerance (the snippet uses 50 units; say the tag spacing if rows are tight).
- Writes D01, D02 … into the NUMBER attribute of each in one AutoLISP pass; a REGEN or entupd shows the new values if the screen doesn't refresh on its own.
- Replies with handle, old and new in a table, so a wrong row order is easy to spot and revert.
The same task in AutoLISP
(progn
(vl-load-com)
(setq ss (ssget "_X" '((0 . "INSERT") (2 . "DOOR-TAG") (66 . 1))) i 0 lst nil n 1)
(if ss
(repeat (sslength ss)
(setq e (ssname ss i) i (1+ i))
(setq lst (cons (cons e (cdr (assoc 10 (entget e)))) lst))))
(setq lst (vl-sort lst '(lambda (a b)
(if (equal (caddr a) (caddr b) 50.0) (< (cadr a) (cadr b)) (> (caddr a) (caddr b))))))
(foreach item lst
(setq att (entnext (car item)))
(while (and att (= (cdr (assoc 0 (entget att))) "ATTRIB"))
(if (= (cdr (assoc 2 (entget att))) "NUMBER")
(entmod (subst (cons 1 (strcat "D" (if (< n 10) "0" "") (itoa n)))
(assoc 1 (entget att)) (entget att))))
(setq att (entnext att)))
(entupd (car item))
(setq n (1+ n)))
(1- n))Tags whose Y is within 50 units count as one row; change 50.0 to suit the plan. Returns how many were renumbered.
Good to know
- "Reading order" is rows from the top; say "clockwise from the entrance" or "by room number" and the sort changes accordingly.
More in draw and lay out
Command: CADSSISTANT
Works in AutoCAD 2024 and newer on Windows. Free trial, no card, no API key.
Get cadssistant