LISP for select all block of same name instead of click on the block i want to type the block name

LISP for select all block of same name instead of click on the block i want to type the block name

paliwal222
Advocate Advocate
3,499 Views
6 Replies
Message 1 of 7

LISP for select all block of same name instead of click on the block i want to type the block name

paliwal222
Advocate
Advocate

LISP for select all block of same name instead of click on the block i want to type the block name

here a lisp for select all block of same name by clicking on one block, but i want to select the block by typing its name.

 

(defun c:fbx ( / blockname sset); filter all blocks of same name with one click
(setq blockname (cdr (assoc 2 (entget (car (entsel))))))
(setq sset (ssget "x" (list (cons 2 blockname))))
(sssetfirst sset sset)
(princ (strcat "\nSelected " (itoa (sslength sset)) " instances of block \"" blockname "\"."))
(princ)
)

0 Likes
Accepted solutions (3)
3,500 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

(defun c:fbx ( / blockname sset); filter all blocks of same name with one click
(setq blockname (getstring t "\nBlock name: "))
(setq sset (ssget "x" (list (cons 2 blockname))))
(sssetfirst sset sset)
(princ (strcat "\nSelected " (itoa (sslength sset)) " instances of block \"" blockname "\"."))
(princ)
)

Message 3 of 7

rkmcswain
Mentor
Mentor
Accepted solution

Does it have to be a lisp routine? You can do this already with the FILTER command in AutoCAD.

 

If you do want to do it with lisp, then:

 

(defun c:fbx ( / blockname sset); filter all blocks of same name with one click
  (setq blockname (getstring t "\nEnter Block Name: "))
  (setq sset (ssget "x" (list (cons 2 blockname))))
  (sssetfirst sset sset)
  (princ (strcat "\nSelected " (itoa (sslength sset)) " instances of block \"" blockname "\"."))
  (princ)
)

 

R.K. McSwain     | CADpanacea | on twitter
Message 4 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

Some refinements I would suggest, to avoid problems resulting from simple typing errors or not knowing whether the Block exists in the drawing:

 

(defun c:fbx ( / blockname sset); filter all blocks of same name with one click
  (while

    (not (tblsearch "block" (setq blockname (getstring t "\nEnter Block Name: "))))

    (prompt "\nNo such Block name defined in this drawing.  Try again:")

  ); while
  (if (setq sset (ssget "x" (list (cons 2 blockname))))

    (progn ; then
      (sssetfirst sset sset)
      (princ (strcat "\nSelected " (itoa (sslength sset)) " instances of block \"" blockname "\"."))

    ); progn

    (prompt "\nNo insertions of that Block in this drawing."); else

  ); if
  (princ)
)

 

And be aware that these suggestions will not work to find Dynamic Blocks, whose insertions don't contain the entry (2 . "BlockName") that the (ssget) filter will look for, but rather an anonymous Block name (2 . "*U...").

Kent Cooper, AIA
Message 5 of 7

paliwal222
Advocate
Advocate
Thanks, Z9E3zK5E its work very well as i want.
now i can make a script in excel to each block put in to layer according name.
Thanks very much
0 Likes
Message 6 of 7

paliwal222
Advocate
Advocate
Thanks, rkmcswain for reply its work very well as i want.
now i can make a script in excel to each block put in to layer according name.
Thanks very much.
0 Likes
Message 7 of 7

paliwal222
Advocate
Advocate
Thanks, Kent1Cooper, for detail information on the point.
Thanks very much
0 Likes