ArchiTECH Tuesday: Swapping AutoCAD Blocks with Autolisp

Date: June 23, 2015

1

I’ve been working on a dynamic block library lately and creating, updating and swapping out one block for another inside AutoCAD Architecture.  Having to repeat the same process always makes me think about improvements and automation.  I cooked this one up last year, but since I’ve been using it heavily this past week, I thought it would make a good addition to the toolkit.

This routine is a modification of a block swapping routine I posted on my blog, BesidetheCursor, way back in June of 2009.  Rather than having to remember the block name when swapping one block for another, I thought it would be more user friendly to simply pick a block and have it swap for another.  You can read my post on the original blkswap routine here: http://wp.me/p5UJ6Z-18

The new version has a minor change.  Open the original autolisp file and locate and swap out the following lines of code:

 (setq newname (getstring “nBlock name to replace with: “))

With these lines of code:

(progn

                (setq new-block (entget (car (entsel “nSelect the new block: “))))

                (setq newname (cdr (assoc 2 new-block)))

                   )

Don’t forget to change the routine definition from blkswap to blkswap2 by changing this line of code:

(defun c:blkswap (/ answr ent idx newname obj ss)

With this line of code:

(defun c:blkswap2 (/ answr ent idx newname obj ss)

Save the file as blkswap2.lsp or download from the link below:

If you have an autoloader already setup, you can add the following code to it:

(autoload “blkswap2” ‘(“blkswap2”))                     ;;;Description: Swap insertions of blocks by each selection with global or single choice

Once this is autoloaded by AutoCAD, simply type the command name blkswap2, select the target block(s), choose single or global, then select the swap block to update the target bloc k with the new swapped block.  You can watch this video to see it in action.

Swapping AutoCAD Blocks with Autolisp from Wakefield Beasley & Associates on Vimeo.

————————-

By: Richard Binning, Director of BIM Technology; Check out his blog: Beside the Cursor; http://www.integr-8.com/