What it does
Equipment Tag Numbering with the EQTAGNO AutoLISP command
Processes selected attributed blocks in selection order and updates one exact attribute tag with a deterministic equipment sequence.
- AutoLISP command
- EQTAGNO
- Difficulty
- Advanced
Applicable disciplines
CAD workflows that use this routine
Requirements and compatibility
What it needs
Software rows marked “Not tested” are not compatibility claims. Test the routine in a copy of your drawing and CAD version.
Downloadable source code
Review the equipment-tag-numbering.lsp AutoLISP code
;; CADLisp Tools - Equipment Tag Numbering
(vl-load-com)
(defun ct-eq:locked-layer-p (name / flags row)
(and (setq row (tblsearch "LAYER" name))
(setq flags (cdr (assoc 70 row)))
(/= 0 (logand flags 20))))
(defun ct-eq:xref-p (data / block flags)
(and data
(setq block (tblsearch "BLOCK" (cdr (assoc 2 data))))
(setq flags (cdr (assoc 70 block)))
(/= 0 (logand flags 12))))
(defun ct-eq:attributes (obj / result)
(setq result (vl-catch-all-apply 'vlax-invoke (list obj 'GetAttributes)))
(if (vl-catch-all-error-p result) nil result))
(defun c:EQTAGNO (/ *error* att attrs data doc ent failed found i number obj prefix
skipped ss step tag undo-started updated write-result wrote)
(defun *error* (message)
(if (and undo-started doc)
(vl-catch-all-apply 'vla-EndUndoMark (list doc)))
(if (and message (not (wcmatch (strcase message) "*CANCEL*,*QUIT*,*EXIT*")))
(prompt (strcat "\nEQTAGNO error: " message)))
(princ))
(setq tag (strcase (getstring T "\nAttribute tag to update: ")))
(if (= tag "")
(prompt "\nAttribute tag cannot be blank.")
(progn
(setq prefix (getstring T "\nTag prefix: ")
number (getint "\nStarting number <1>: "))
(if (null number) (setq number 1))
(initget 2)
(setq step (getint "\nIncrement (non-zero) <1>: "))
(if (null step) (setq step 1))
(prompt "\nSelect attributed equipment blocks in sequence: ")
(if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
(progn
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object))
undo-started (not (vl-catch-all-error-p
(vl-catch-all-apply 'vla-StartUndoMark (list doc))))
i 0 updated 0 skipped 0 failed 0)
(repeat (sslength ss)
(setq ent (ssname ss i) data (and ent (entget ent)) found nil wrote nil)
(if (and data
(not (ct-eq:xref-p data))
(not (ct-eq:locked-layer-p (cdr (assoc 8 data))))
(not (vl-catch-all-error-p
(setq obj (vl-catch-all-apply 'vlax-ename->vla-object (list ent))))))
(progn
(setq attrs (ct-eq:attributes obj))
(foreach att attrs
(if (= (strcase (vla-get-TagString att)) tag)
(progn
(setq found T
write-result
(vl-catch-all-apply 'vla-put-TextString
(list att (strcat prefix (itoa number)))))
(if (vl-catch-all-error-p write-result)
(setq failed (1+ failed))
(setq wrote T)))))))
(if wrote
(setq updated (1+ updated) number (+ number step))
(setq skipped (1+ skipped)))
(setq i (1+ i)))
(if undo-started
(progn (vla-EndUndoMark doc) (setq undo-started nil)))
(prompt (strcat "\nUpdated " (itoa updated) "; skipped " (itoa skipped)
"; write failures " (itoa failed) ".")))
(prompt "\nNo attributed blocks selected."))))
(princ))
Setup
How to install the equipment-tag-numbering.lsp file
- 1Download and review the source code.
- 2Load the .lsp file with APPLOAD in a copy of a drawing.
- 3Keep the routine session-only until it has been tested for your CAD version and standards.
Command workflow
How to run the EQTAGNO command
- 1Run EQTAGNO.
- 2Enter the attribute tag, prefix, start, and non-zero increment.
- 3Select blocks in the required order.
Worked example
Example: Number equipment TAG attributes AHU-01 onward.
- Enter TAG and AHU-.
- Start at 1 with increment 1.
- Select blocks in order.
Matching attributes receive the sequence.
Read before use
Notes and limitations
- Selection order controls numbering.
- Blocks missing the exact attribute tag are skipped.
- Not manually CAD-tested.
Version history