find block by selected text

find block by selected text

E.S.7.9
Advocate Advocate
1,152 Views
4 Replies
Message 1 of 5

find block by selected text

E.S.7.9
Advocate
Advocate

hello

 

i have text list in my drawing and these text values also embedded to block names .. i wanted to find blocks which contain selected text value via lisp 

could anybody share with me the lisp code something like that . please ? 

thank you 

0 Likes
Accepted solutions (2)
1,153 Views
4 Replies
Replies (4)
Message 2 of 5

dbhunia
Advisor
Advisor

Post a sample drawing...... 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 5

E.S.7.9
Advocate
Advocate

i attached simple drawing which explains what i eant to do ..

 

thanks again

0 Likes
Message 4 of 5

dbhunia
Advisor
Advisor
Accepted solution

Try this......

 

(defun c:sbbt (/ st ss ssb N)
(vl-load-com)
(setvar 'cmdecho 0)
(setq st (cdr (assoc 1 (entget(car(entsel "\nSelect Text..."))))))
(setq ss (ssget "_A" '((0 . "INSERT"))))
(setq ssb (ssadd))
(repeat (setq N (sslength ss))
	(setq Data (ssname SS (setq N (- N 1))))
	(setq EntityData (entget Data))
	(setq bn (cdr (assoc 2 EntityData)))
	(if (/= nil (vl-string-search st bn)) (ssadd Data ssb))
)
(if (/= 0 (sslength ssb)) (sssetfirst nil ssb)(princ "\nNo Block Found by this Name....."))
(setvar 'cmdecho 1)
(princ)
)

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 5

ronjonp
Mentor
Mentor
Accepted solution

Alternatively you could filter directly like so:

(defun c:foo (/ e s)
  (cond	((and (setq e (car (entsel "\nPick your text: "))) (setq s (cdr (assoc 1 (entget e)))))
	 (setq s (ssget "_X" (list '(0 . "insert") (cons 2 (strcat "*" s "*")))))
	 (and s (sssetfirst nil s) (print (strcat (itoa (sslength s)) " blocks found...")))
	)
  )
  (princ)
)
0 Likes