;(C) 2010 CAD Studio - www.cadstudio.cz
;select all blocks like selected block(s)

(defun C:SELBLK ( / e ss) ; single
 (setq e (entsel "\nSelect a block name to select: "))
 (if e (setq ss (ssget "_X" (list(cons 2 (cdr (assoc 2 (entget (car e)))))(cons 0 "INSERT")))))
 (if (zerop (getvar "CMDACTIVE"))
  (progn (sssetfirst ss ss)(princ "Use 'P' for this selection set: ")(princ))
   ss
 )
)

(defun C:SELBLKS ( / e blk ss blkl) ; multiple
 (setq blkl ""  ss (ssadd))
 (while (setq e (entsel "\nSelect next block name to select <exit>: "))
  (setq blkl (strcat blkl "," (cdr (assoc 2 (entget (car e))))))
  (princ (substr blkl 2))
 );while
 (setq blkl (substr blkl 2))
 (if (> blkl "") (setq ss (ssget "_X" (list (cons 2 blkl)(cons 0 "INSERT")))))
 (if (zerop (getvar "CMDACTIVE"))
  (progn (sssetfirst ss ss)(princ "Use 'P' for this selection set: ")(princ))
   ss
 )
)

(defun C:SELBLKN ( / e ss) ; by name
 (setq e (getstring T "\nType block name(s) to select (comma-delimited list or wildcards): "))
 (if (> e "") (setq ss (ssget "_X" (list (cons 2 e)(cons 0 "INSERT")))))
 (if (zerop (getvar "CMDACTIVE"))
  (progn (sssetfirst ss ss)(princ "Use 'P' for this selection set: ")(princ))
   ss
 )
)

(princ "\nCADstudio SELBLK + SELBLKS + SELBLKN commands loaded.")(princ)
