;;; BeekeeCZ Isolate Blocks by Name
;;; Saved from: http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/isolate-block-without-turning-off/td-p/6487237
;;; Slightly modified by Igal Averbuh 2017 (added option to unisolate selected blocks)

; 1st select patern blocks (regular, not dynimacs blks) - it could be in model space or in layout.
; ... you can select all blocks within a boundary (boudaries)
; 2nd for defying the area you can use a classics selection window (inc. lasso) or select exists boundary object (closed *polyline, circle, ellipse)
; no boundaries, no limits.... it selects all filtred blocks in model space
; 1+2 and selects all block within model space.
; 3rd desired blocks are isolated

(vl-load-com)

(defun c:Ib ( / _pac ss new temp en i i2)

;; Based on routine written by Alan J. Thompson, 03.31.11
;; http://www.cadtutor.net/forum/showthread.php?57864-How-to-select-all-objects-enclosed-in-a-poly-line&p=392378&viewfull=1#post392378

(defun _pac (e / l v d lst)
(setq d (- (setq v (/ (setq l (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))) 100.))))
(while (< (setq d (+ d v)) l)
(setq lst (cons (vlax-curve-getPointAtDist e d) lst))))

(if (and (princ "\nSelect blocks for isolate: ")
(or (and (setq ss (cond ((ssget "_I" '((0 . "INSERT"))))
((ssget '((0 . "INSERT"))))))
(setq blocks "")
(repeat (setq i (sslength ss))
(setq blocks (strcat (cdr (assoc 2 (entget (ssname ss (setq i (1- i)))))) "," blocks)))
(setq blocks (vl-string-trim "," blocks))
(sssetfirst nil nil)
)
(setq blocks "*")
)
(or (if (/= "Model" (getvar 'CTAB)) (setvar 'CTAB "Model"))
T)
(setq new (ssadd))
(princ "\nSelect filtering area or press Enter to select all blocks within drawing: ")
(or (and (setq ss (ssget (list '(-4 . "<OR")
'(0 . "CIRCLE,ELLIPSE")

'(-4 . "")

'(-4 . "")

'(-4 . "OR>")
)))
(repeat (setq i (sslength ss))
(if (= "INSERT" (cdr (assoc 0 (entget (setq en (ssname ss (setq i (1- i))))))))
(ssadd en new)
(if (setq temp (ssget "_WP" (_pac en) (list '(0 . "INSERT") (cons 2 blocks))))
(repeat (setq i2 (sslength temp))
(ssadd (ssname temp (setq i2 (1- i2))) new)))))
)
(setq new (ssget "_X" (list '(0 . "INSERT")
(cons 2 blocks)
'(410 . "Model"))))
)
)
(command "_.ISOLATEOBJECTS" new ""))

(princ "\nType UB to UNISOLATE Selected Blocks")

(princ)
)
(c:ib)

(defun c:ub ( / )

(command "_.UNISOLATEOBJECTS" new "")
)

Advertisements