CADLisp Tools

Data Extraction

BOM from Block Attributes AutoLISP routine

Count selected blocks by one chosen attribute value. Download the .LSP source below and run the BLOCKBOM command after loading it.

⌘ BLOCKBOMv1.0.0AdvancedUpdated Sep 18, 2026

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

AutoLISPVisual LISPActiveX

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

bom-from-block-attributes.lspAUTOLISP
;; 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

  1. 1Download and review the source code.
  2. 2Load the .lsp file with APPLOAD in a copy of a drawing.
  3. 3Keep the routine session-only until it has been tested for your CAD version and standards.

Command workflow

How to run the BLOCKBOM command

  1. 1Run BLOCKBOM.
  2. 2Enter the attribute tag to group by.
  3. 3Select attributed blocks and read the summary.

Worked example

Example: Count parts by PARTNO.

  1. Run BLOCKBOM.
  2. Enter PARTNO.
  3. Select assembly blocks.
Expected result

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

Changelog

v1.0.0Sep 18, 2026Initial attribute-value quantity summary.

Keep automating

Related tools

Blocks & Attributes6 disciplines

Count Selected Blocks

Summarize selected block references by name in the command line.

⌘ COUNTBLOCKSIntermediateCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →
Blocks & Attributes4 disciplines

Equipment Tag Numbering

Write a prefix and sequential number into a chosen block attribute.

⌘ EQTAGNOAdvancedCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →
Data Extraction6 disciplines

Export Block Attributes to CSV

Export selected block names and attribute tag/value pairs to a CSV file.

⌘ ATTCSVAdvancedCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →