What it does
Select Same Blocks with the SELSAMEBLOCKS AutoLISP command
Uses one picked block as the pattern and highlights matching INSERT entities in the current model or paper-space layout, resolving dynamic-block effective names through ActiveX.
- AutoLISP command
- SELSAMEBLOCKS
- Difficulty
- Intermediate
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 select-same-blocks.lsp AutoLISP code
;; CADLisp Tools - Select Same Blocks
(vl-load-com)
(defun ct-sb: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:SELSAMEBLOCKS (/ all data ent i name out pick test-name)
(cond
((null (setq pick (entsel "\nPick a block reference: ")))
(prompt "\nNo object selected."))
((or (null (setq data (entget (car pick))))
(/= (cdr (assoc 0 data)) "INSERT"))
(prompt "\nThe selected object is not a block reference."))
((null (setq name (ct-sb:name (car pick))))
(prompt "\nThe block name could not be read."))
(T
(setq out (ssadd)
all (ssget "_X" (list '(0 . "INSERT") (cons 410 (getvar "CTAB")))))
(if all
(progn
(setq i 0)
(repeat (sslength all)
(setq ent (ssname all i) test-name (ct-sb:name ent))
(if (and test-name (= (strcase test-name) (strcase name))) (ssadd ent out))
(setq i (1+ i)))))
(sssetfirst nil out)
(prompt (strcat "\nSelected " (itoa (sslength out))
" matching block(s) in the current layout."))))
(princ))
Setup
How to install the select-same-blocks.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 SELSAMEBLOCKS command
- 1Run SELSAMEBLOCKS.
- 2Pick a block reference.
- 3Review the matching references highlighted in the current layout.
Worked example
Example: Select every instance of a door-symbol block.
- Run SELSAMEBLOCKS.
- Pick one door symbol.
- Review the selection.
References with the same effective block name in the current layout are selected.
Read before use
Notes and limitations
- Does not inspect nested blocks.
- Requires ActiveX to resolve dynamic-block effective names.
- Not manually CAD-tested.
Version history