- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there,
This lisp below is from Lee MAC. I was attached here as well. It selects blocks based on block name, tag and attribute in the current layout. Could you please make some modification to select the blocks in all layouts in the same file? thank you very much in advance. 🙂
;; Block Selection - Lee Mac
;; Selects all blocks in the current layout with a given block name or which contain a specified attribute tag and/or value.
(defun c:bsel ( / att atx blk cnt ent enx flg idx sel str tag )
(setq blk (strcase (getstring t "\nSpecify block name <any>: "))
tag (strcase (getstring "\nSpecify attribute tag <any>: "))
str (strcase (getstring t (strcat "\nSpecify attribute value" (if (= "" tag blk) ": " " <any>: "))))
)
(if (not (= "" str tag blk))
(if
(and
(setq sel
(ssget "_X"
(append
'((000 . "INSERT"))
(if (not (= "" tag str)) '((066 . 1)))
(if (/= "" blk) (list (cons 2 (strcat "`*U*," blk))))
(if (= 1 (getvar 'cvport))
(list (cons 410 (getvar 'ctab)))
'((410 . "Model"))
)
)
)
)
(progn
(repeat (setq idx (sslength sel))
(setq ent (ssname sel (setq idx (1- idx)))
enx (entget ent)
)
(cond
( (not (or (= "" blk) (wcmatch (strcase (LM:name->effectivename (cdr (assoc 2 enx)))) blk)))
(ssdel ent sel)
)
( (member (cdr (assoc 66 enx)) '(nil 0)))
( (progn
(setq att (entnext ent)
atx (entget att)
flg nil
)
(while
(and (= "ATTRIB" (cdr (assoc 0 atx)))
(not
(and
(or (= "" str) (wcmatch (strcase (cdr (assoc 1 atx))) str))
(or (= "" tag) (wcmatch (strcase (cdr (assoc 2 atx))) tag))
)
)
)
(setq att (entnext att)
atx (entget att)
)
)
(= "SEQEND" (cdr (assoc 0 atx)))
)
(ssdel ent sel)
)
)
)
(< 0 (setq cnt (sslength sel)))
)
)
(progn
(princ (strcat "\n" (itoa cnt) " block" (if (= 1 cnt) "" "s") " found."))
(sssetfirst nil sel)
)
(princ "\nNo blocks found.")
)
)
(princ)
)
;; Block Name -> Effective Block Name - Lee Mac
;; blk - [str] Block name
(defun LM:name->effectivename ( blk / rep )
(if
(and (wcmatch blk "`**")
(setq rep
(cdadr
(assoc -3
(entget
(cdr (assoc 330 (entget (tblobjname "block" blk))))
'("acdbblockrepbtag")
)
)
)
)
(setq rep (handent (cdr (assoc 1005 rep))))
)
(cdr (assoc 2 (entget rep)))
blk
)
)
(princ)
Solved! Go to Solution.