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)
)

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.

14 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

  8. ram says:

    hi thanks for sharing what about if attributes are there.?

  9. Muhsin says:

    Hi there,
    is it possible instead of autonaming the block, to select a mtext or txt for the block name? it would be very helpful…

    thanks for the lisp

  10. Muhsin says:

    Hi,
    Is it possible to get the name for the block from a mtext? That would be a perfecr lisp for me?

    Thanks…

  11. Hashub says:

    Really appreciate that

  12. Thomas says:

    This is great!

    I was having trouble with the block command because I was using a list of entities instead of a selection set.

    Thanks Greg!!

Leave a comment