Once a dynamic parameter is changed in a dynamic block, the default command SELECTSIMILAR won’t work. So this is a workaround to select dynamic blocks by name.
It also features a command to select blocks by specific attribute value. This works in cascade so you can filter the resulting selection by picking another attribute.
Commands:
- DYNBLOCK_SIMILAR – Selects all the dynamic blocks with the same name.
- ATTVAL_SIMILAR – Selects all the blocks with the same attribute value by picking the block attribute.
AutoLISP code
Lisp
(vl-load-com)
(princ
(strcat
"\nProgram to select dynamic blocks by name"
"\nCommands: "
"\nDYNBLOCK_SIMILAR - Selects all dynamic blocks with the same name. Once a dynamic parameter is changed in a block the default SELECTSIMILAR won't work."
"\nATTVAL_SIMILAR - Selects all blocks with the same attribute value. "
"\n\t\t\t\t\t\t\t\tWorks in cascade so you can filter the resulting selection by picking another attribute."
"\n(c) "
(substr (rtos (getvar "CDATE") 2 0) 1 4)
" lisp-solutions.com"
)
)
(princ)
(defun C:DYNBLOCK_SIMILAR (/ bname blk ss i e)
(if
(and
(if
(and (setq ss (ssget "_A" '((0 . "INSERT"))))
(setq ss (LS:SS_VISIBLE ss))
)
t
(progn
(princ "\nNo blocks in the drawing.")
nil
)
)
(if
(and (setq blk (car (entsel "\nPick block>>")))
(eq "INSERT" (cdr (assoc 0 (entget blk)))) ;;; npad
)
(setq bname (getpropertyvalue blk "BlockTableRecord/Name"))
(progn
(princ "\nNo block selected")
nil
)
)
)
(repeat (setq i (SSLENGTH ss))
(setq e (ssname ss (setq i (1- i))))
(if (/= bname (getpropertyvalue e "BlockTableRecord/Name"))
(setq ss (ssdel e ss))
)
)
)
(if (and ss (zerop i))
(progn
(SSSETFIRST ss ss)
(princ (strcat "\n" (itoa (SSLENGTH ss)) " blocks found"))
)
(princ "\nNo blocks found.")
)
(princ)
)
(defun C:ATTVAL_SIMILAR (/ bname blk ss i e att att_dx att_key att_val)
(if
(and
(if
(cond ((setq ss (ssget "_I" '((0 . "INSERT")))))
((and (setq ss (ssget "_A" '((0 . "INSERT"))))
(setq ss (LS:SS_VISIBLE ss))
)
)
)
t
(progn
(princ "\nNo blocks in the drawing.")
nil
)
)
(if (setq att (car (nentsel "\nPick block attribute>>")))
(progn
(setq att_dx (entget att))
(setq att_key (cdr (assoc 2 att_dx)))
(setq att_val (cdr (assoc 1 att_dx)))
)
(progn
(princ "\nNo attribute selected")
nil
)
)
(if (setq blk (cdr (assoc 330 att_dx)))
(setq bname (getpropertyvalue blk "BlockTableRecord/Name"))
(progn
(princ "\nThe selected attribute has no parent")
nil
)
)
)
(repeat (setq i (SSLENGTH ss))
(setq e (ssname ss (setq i (1- i))))
(if
(or
(/= bname (getpropertyvalue e "BlockTableRecord/Name"))
(/= att_val (getpropertyvalue e att_key))
)
(setq ss (ssdel e ss))
)
)
)
(if (and ss att_key att_val (zerop i))
(progn
(SSSETFIRST ss ss)
(princ
(strcat "\nFound "
(itoa (SSLENGTH ss))
" blocks with "
att_key
" = "
att_val
)
)
)
(princ "\nNo blocks found.")
)
(princ)
)
(defun LS:SS_VISIBLE (ss / ss_res la e i)
(setq ss_res (ssadd))
(repeat (setq i (sslength ss))
(setq e (ssname ss (setq i (1- i))))
(setq la (tblsearch "LAYER" (cdr (assoc 8 (entget e)))))
(if (< 0 (cdr (assoc 62 la)))
(setq ss_res (ssadd e ss_res))
)
)
ss_res
)
;;;EOF