CADLisp Tools

Blocks & Attributes

Count Selected Blocks AutoLISP routine

Summarize selected block references by name in the command line. Download the .LSP source below and run the COUNTBLOCKS command after loading it.

⌘ COUNTBLOCKSv1.1.0IntermediateUpdated Sep 18, 2026

What it does

Count Selected Blocks with the COUNTBLOCKS AutoLISP command

A compact quantity-checking helper for fixtures, devices, symbols, and repeated components. It counts INSERT entities in a deliberate selection and prints an alphabetical summary.

AutoLISP command
COUNTBLOCKS
Difficulty
Intermediate

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 count-blocks.lsp AutoLISP code

count-blocks.lspAUTOLISP
;; CADLisp Tools - Count Selected Blocks
(vl-load-com)

(defun ct-cb: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-cb:name (ent / data obj result)
  (setq data (and ent (entget ent)))
  (if data
    (progn
      (setq obj (vl-catch-all-apply 'vlax-ename->vla-object (list ent)))
      (if (not (vl-catch-all-error-p obj))
        (progn
          (if (vlax-property-available-p obj 'EffectiveName)
            (setq result (vl-catch-all-apply 'vla-get-EffectiveName (list obj))))
          (if (or (null result) (vl-catch-all-error-p result))
            (setq result (vl-catch-all-apply 'vla-get-Name (list obj))))))
      (if (or (null result) (vl-catch-all-error-p result))
        (setq result (cdr (assoc 2 data))))
      result)))

(defun c:COUNTBLOCKS (/ counts ent index name pair set skipped)
  (prompt "\nSelect block references to count: ")
  (if (setq set (ssget '((0 . "INSERT"))))
    (progn
      (setq index 0 counts nil skipped 0)
      (repeat (sslength set)
        (setq ent (ssname set index) name (ct-cb:name ent))
        (if name
          (setq counts (ct-cb:bump name counts))
          (setq skipped (1+ skipped)))
        (setq index (1+ index)))
      (setq counts (vl-sort counts '(lambda (a b) (< (strcase (car a)) (strcase (car b))))))
      (prompt "\n--- Block count (dynamic effective names) ---")
      (foreach pair counts (prompt (strcat "\n" (car pair) ": " (itoa (cdr pair)))))
      (prompt (strcat "\nInvalid references skipped: " (itoa skipped))))
    (prompt "\nNo block references selected."))
  (princ))

Setup

How to install the count-blocks.lsp file

  1. 1Download and review the source.
  2. 2Load it with APPLOAD.
  3. 3Open command history to copy the summary.

Command workflow

How to run the COUNTBLOCKS command

  1. 1Run COUNTBLOCKS.
  2. 2Select block references.
  3. 3Press Enter and read the alphabetical count.

Worked example

Example: Check the quantity of selected fixture symbols.

  1. Run COUNTBLOCKS.
  2. Select the plan area.
  3. Review the block-name totals.
Expected result

A block-by-block quantity summary appears in command history.

Read before use

Notes and limitations

  • Uses ActiveX to resolve dynamic-block effective names.
  • Does not inspect nested blocks.
  • Does not export a BOM file.
  • Not manually CAD-tested.

Version history

Changelog

v1.1.0Sep 18, 2026Resolve dynamic-block effective names and skip invalid references safely.
v1.0.0Sep 14, 2026Initial starter implementation.

Keep automating

Related tools

Data Extraction4 disciplines

BOM from Block Attributes

Count selected blocks by one chosen attribute value.

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

Select Same Blocks

Select same-name block references, including dynamic block references.

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