What it does
BOM from Block Attributes with the BLOCKBOM AutoLISP command
Reads a requested attribute tag from selected blocks, groups identical values, and prints a compact quantity summary for BOM preparation.
- AutoLISP command
- BLOCKBOM
- 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 bom-from-block-attributes.lsp AutoLISP code
;; CADLisp Tools - BOM from Block Attributes
(vl-load-com)
(defun ct-bb:bump (key items / hit)
(if (setq hit (assoc key items))
(subst (cons key (1+ (cdr hit))) hit items)
(cons (cons key 1) items)))
(defun ct-bb:invoke-list (obj method / result)
(setq result (vl-catch-all-apply 'vlax-invoke (list obj method)))
(if (vl-catch-all-error-p result) nil result))
(defun ct-bb:attributes (obj)
(append (ct-bb:invoke-list obj 'GetAttributes)
(ct-bb:invoke-list obj 'GetConstantAttributes)))
(defun ct-bb:property (object getter / result)
(setq result (vl-catch-all-apply getter (list object)))
(if (vl-catch-all-error-p result) nil result))
(defun c:BLOCKBOM (/ att attrs counts ent i obj pair skipped ss tag tag-name value)
(setq tag (strcase (getstring T "\nAttribute tag to group by: ")))
(if (= tag "")
(prompt "\nAttribute tag cannot be blank.")
(progn
(prompt "\nSelect attributed blocks: ")
(if (setq ss (ssget '((0 . "INSERT"))))
(progn
(setq i 0 counts nil skipped 0)
(repeat (sslength ss)
(setq ent (ssname ss i)
obj (and ent (vl-catch-all-apply 'vlax-ename->vla-object (list ent)))
value nil)
(if (and obj (not (vl-catch-all-error-p obj)))
(progn
(setq attrs (ct-bb:attributes obj))
(foreach att attrs
(setq tag-name (ct-bb:property att 'vla-get-TagString))
(if (and tag-name (= (strcase tag-name) tag))
(setq value (ct-bb:property att 'vla-get-TextString))))))
(if value
(setq counts (ct-bb:bump value counts))
(setq skipped (1+ skipped)))
(setq i (1+ i)))
(prompt "\n--- Attribute BOM ---")
(foreach pair (vl-sort counts '(lambda (a b) (< (strcase (car a)) (strcase (car b)))))
(prompt (strcat "\n" (if (= (car pair) "") "<blank>" (car pair))
": " (itoa (cdr pair)))))
(prompt (strcat "\nBlocks missing a readable matching tag: " (itoa skipped))))
(prompt "\nNo attributed blocks selected."))))
(princ))
Setup
How to install the bom-from-block-attributes.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 BLOCKBOM command
- 1Run BLOCKBOM.
- 2Enter the attribute tag to group by.
- 3Select attributed blocks and read the summary.
Worked example
Example: Count parts by PARTNO.
- Run BLOCKBOM.
- Enter PARTNO.
- Select assembly blocks.
Each distinct PARTNO value and quantity is printed.
Read before use
Notes and limitations
- Prints a summary; it does not create a native table or CSV.
- Blocks missing the requested tag are skipped.
- Not manually CAD-tested.
Version history