AutoLISP: Select block by name

Even though, you can use the SELECTSIMILAR [found here] command to select a block and then this command will select the other blocks like the selected block…Here is a LISP rouinte that will make a selection set of a named block.

Here’s how:
Edit the below lisp routine to select that you want selected. To do this, change the word “test” to the name of your block within quotes.
Save the lisp routine…

SELECTBLOCK <enter>

that’s all…

 

Thanks to Tharwat and him being extremely patient, he made many variations to this program.

The code in its various revisions can be found here: http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/selection-set-by-block-name/m-p/5192827/highlight/true#M324878

Advertisements

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, AutoLISP: Blocks, AutoLISP: Modify. Bookmark the permalink.

12 Responses to AutoLISP: Select block by name

  1. Kent Cooper says:

    There’s really no need to find all Blocks and step through them one at a time to determine whether they have the right name. You can eliminate some variables and the whole (repeat) function and some other bits and pieces, by doing just:
    (sssetfirst nil (ssget “_X” ‘((0 . “INSERT”) (2 . “TEST”))));;;;;;;change the Block name

    • AutoCAD Tips says:

      Kent,
      That sounds simple enough… The next thing I was going to do was modify this to select multiple named blocks. Would your method do that easily?
      Note: I have had barely any time to put stuff together for the blog since I started teaching about a month ago…

      • Kent Cooper says:

        You can use wildcards and multiple patterns as described for (wcmatch), in the case of multiple Block names, stringing them together with comma separators:
        (sssetfirst nil (ssget “_X” ‘((0 . “INSERT”) (2 . “test1,test2,test3”))))

    • Hi Kent ,

      I have just read this article that brought by a guy that I helped before and noticed your reply against it , so although that the program is quite old and I could offer another one that would be mush better in performance , I wanted to tell you that I did the iteration to obtain Dynamic blocks as well as the standard / Normal blocks cause to just add the block in the filter of the ssget function , that doesn’t work with dynamic blocks .
      Tharwat

      • AutoCAD Tips says:

        I am going to update my post so that it doesn’t have the code posted, but rather a link to the programs. That guy had so many pages of “almost , but can you change this and that…”
        Thanks for your work Tharwat

  2. Kent Cooper says:

    Oh, and following on my previous comment: It’s not even case-sensitive, so the (strcase) functions are not needed. The Block name, and even the “insert” entity type in the selection-set filter, can be in either (or even mixed) case.

  3. Eduard says:

    I want to plot my selected blocks. is that possible?

    • AutoCAD Tips says:

      I am not aware of any option to plot selected objects or blocks. I am pretty sure that the options ar elimited to plotting areas of your drawings.
      The only thing i can think of to help achieve your request is to WBLOCK individual blocks out to their own files and then plotting those drawings.
      ~Greg

  4. iDeeW says:

    I want to send the search name from the AutoCAD command line……
    So is this correct?

    (defun c:SelectBlock (b / blkname found objs ss i blk name)
    (vl-load-com)
    ;;; Tharwat 03. March. 2012 ;;;
    (if (and (setq blkname b)……………………………………….
    ……………………………………..etc…

    But this gives me an error…”no function definition:SelectBlock”

    Thanks

  5. Pingback: مقدمة لتعلم الاتوليسب | OMAR SELIM

  6. Amr Aly says:

    Could you please send me the code , i can not find it.

  7. loyoro says:

    Could you please send me the code

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s