AutoLISP: Make a Block Quickly

Here is a handy routine that will let you quickly create a block of selected objects – it will even automatically name the block for you.

Here’s how:

  • QB <enter> to start (Quick Block)
  • Select the objects that you want the block to be made of <enter>
  • Specify an Insertion point
  • The routine will automatically give the block a generic name “MyBlock” followed by a number. Each time you use the routine to create a quick block, the number will increase incrementally  (ex. MyBlock1, MyBlock2, MyBlock3…)
  • Note – Use on blocks that do not have attributes – use on geometry only

~enjoy



; Quick Block
; Creates a block instantly out of the objects that you select
; Found at http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Quick-block/td-p/3454228
(defun c:QB (/ selectionset insertionpoint number Blockname)
  ;;; Tharwat 11. May. 2012 ;;
  (if (and (setq selectionset (ssget "_:L"))
           (setq insertionpoint (getpoint "\n Specify insertion point :"))
      )
    (progn
      (setq number    1
            Blockname (strcat "MyBlock" (itoa number))
      )
      (while (tblsearch "BLOCK" Blockname)
        (setq Blockname
               (strcat "MyBlock" (itoa (setq number (1+ number))))
        )
      )
      (command "_.-Block" Blockname insertionpoint selectionset "")
      (command "_.-insert" Blockname insertionpoint "" "" "")
    )
    (princ)
  )
  (princ)
)
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: Creating. Bookmark the permalink.

9 Responses to AutoLISP: Make a Block Quickly

  1. andres says:

    Thanks!!
    Very useful, I had to make 50 blocks and this saved my life ;-)

  2. You may use a couple of commands to make it, such as ctrl+x after that ctrl+shift+v. I will get a new block

  3. peppemaz says:

    Unable to load in Autocad2014

    • AutoCAD Tips says:

      i just tested it in both 2014 & 2015 and it is working. I think that the issue that you are experiencing is the new “SECURELOAD” feature.
      Type SECURELOAD in the command line and hit enter. Then set it to 0 (zero)
      Then you should be able to load these easily.
      ~Greg

  4. Rebecca says:

    Thanks for the great tip. I’m wondering how I would modify this to automatically get all the objects on the current layer, create the block using the current layer name with a 0,0,0 base point and then insert the block at its original position. Thanks in advance!

  5. Darroes says:

    Thanks, it’s very help full. before i use this lisp, i got confused use CTRL+SHIFT+C then CTRL+SHIFT+V and cause of that my block got a random name. it’s hard to find if we have more than 20 block with a typical design.
    Thanks for advice

  6. djafri says:

    Cherchez comment dire point d l’intersection de deux lignes dans AutoCAD LISP

  7. bora says:

    hi i need this lisp which automatically sets insertion point to 0,0,0
    i want to just select and enter and then have a random named block with just one clik

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