Convert muliple circles to autocad blocks
A friend ask me if there is a quicker way to insert Autocad blocks in replacement to the circles in his drawing instead of inserting the block one by one manually. I answered him, “Yes, there is.”
Instead of inserting the new block one at a time, why don’t we create a lisp and automate the tedious block insertion process. By using the center point of the circles, we can create a lisp routine that will make a block and insert it in the specific center point of the circle auto-magically! This will save you many hours of drafting time compare to doing it the traditional way. If you have 3-4 circles to be replaced by block then that is tolerable but what if you have thousands of circles - that will surely be a tough job.
Here let me share you how to shortcut this long traditional method of inserting block on the centerpoint of each circle.
First, we have to create a lisp routine that is capable of converting multiple circles to block and insert it in the circle’s centerpoint automatically. Then, we will load that lisp to your autocad drawing and with a single command ^puff^ your circles will become blocks. You may use this block later so you can convert this to Electrical Device, change the symbology or whatever autocad mep 2008 manipulation you want to do.
Create the Circle-to-Block Autolisp:
- Open notepad.exe
- Copy and paste the code below
(defun groupCircle (obj lst / rad ) (setq rad (vla-get-radius obj) rad (cond ((> rad 10000) 10000)((> rad 5000) 5000)((> rad 1000) 1000) ((> rad 500) 500)((> rad 475) 475)((> rad 450) 450)((> rad 425) 425) ((> rad 400) 400)((> rad 375) 375)((> rad 350) 350)((> rad 325) 325) ((> rad 300) 300)((> rad 275) 275)((> rad 250) 250)((> rad 225) 225) ((> rad 200) 200)((> rad 175) 175)((> rad 150) 150)((> rad 125) 125) ((> rad 100) 100)((> rad 75) 75)((> rad 50) 50)((> rad 25) 25)(T 1))) (if (assoc rad lst) (subst (cons rad (append (cdr (assoc rad lst))(list obj)))(assoc rad lst) lst) (append lst (list (list rad obj))) ) ) (defun makeBlockCircle (blockname rad / ip blkobj sArray) (setq BlkCol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) pto (vlax-3D-point ‘(0.0 0.0 0.0)) BlkBal (vla-add BlkCol pto blockname) blkobj (vla-addCircle BlkBal pto rad) ) ) (defun c:RepCir2Blk ( / i ss obj CiLst blkNm) (vl-load-com) (if (setq CiLst nil i 0 ss (ssget ‘((0 . “circle”)))) (progn (setq *doc* (vla-get-activedocument (vlax-get-acad-object))) (while (< i (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss i)) CiLst (groupCircle obj CiLst) i (1+ i)) ) (foreach cir CiLst (setq blkNm (strcat “Circle” (itoa (car cir)))) (if (not (tblsearch “block” blkNm))(makeBlockCircle blkNm (car cir))) (foreach cirobj (cdr cir) (if (vla-insertblock (vla-get-ModelSpace *Doc*) (vla-get-center cirobj) blkNm 1 1 1 0) (vla-delete cirobj) ) ) ) ) ) (princ) )
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, “Courier New”, courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }
- In the notepad, saveas the file inside the folder where you want the lisp to be stored.
- Specify filename, e.g. RepCir2Blk.lsp (Don’t forget the “.lsp” extension”
- Click saveas type, choose “All files”.
- Hit the save button.
The Replace Circle to Block (RerCir2Blk) in action
- Open the autocad file that contains the circles you want to convert to blocks.
- In the command box, type “appload”
- Browse and load the RepCir2Blk lisp you created in step 4 above.
- Once the lisp is loaded, close the Load/Upload application dialog box
- You can now use convert circles to block simultaneously, by running the command: RepCir2Blk.
If in your first attempt the steps here didn’t work, I suggest you repeat step one and follow the procedure carefully.
This technique is very useful specially if you are working in Autocad MEP 2008. Most of the time you’ll receive drawings from consultant or from third party for MEP detailed drawings. There are those who provide the drawing in plain autocad with the drawing blocks intact, but there are cases where you’ll receive drawings with exploded content. Electrical symbols, upright and downright sprinklers might be represented with plain circles. In this case converting those circles to Autocad MEP device or mvpart will be forever, as you are going to insert the device or mvpart one by one . But if they are in block then there is a simple procedures that will easily convert these Autocad blocks into device or sprinkler mvparts with less hassle.
You’ll know how to do it in my coming post. so Stay tuned.
If you think this tip is useful then don’t be shy to share it to others. You might as well subscribe our feed via email so you’ll receive the latest Autocad MEP tips and tricks to your inbox, or subscribe via your favorite feedreader.



May 28th, 2008 at 6:54 pm
How can I convert multiple points to blocks via lisp or vba?
Thanks - Ray
May 29th, 2008 at 9:53 am
with a little lisp modification we can do it with the same process as above..
i’m going to post the exact routine soon.
see you around.
August 17th, 2008 at 6:49 pm
I have tried this lisp for replacing circles with block but it doesn,t work in any of the autocad versions higher than 2000 t=which i have,,, can you help?
August 18th, 2008 at 8:23 am
I used autocad 2008 for this lisp and it works for me..
October 3rd, 2008 at 7:16 am
I tried it in AutoCAD 2008 and recieved
Command: _appload repcir2blk.lsp successfully loaded.
Command: ; error: bad argument type: consp “CIRCLE”
Could help - I am not master in lisp.
October 4th, 2008 at 9:00 am
don’t work for me too (Autocad 2006), but I found working lisp:
(defun C:C2BLK ( / ss blk ent pt n)
(prompt “\nSelect Circles to replace: “)
(setq ss (ssget ‘((0 . “CIRCLE”)))
blk (getstring “\nName of Block: “)
);;setq
(if (and ss (tblsearch “block” blk))
(progn
(setq n (1- (sslength ss)))
(while (>= n 0)
(setq ent (ssname ss n)
pt (cdr (assoc 10 (entget ent)))
n (1- n)
);; setq
(command “_.-insert” blk pt “” “” “”)
);;while
(command “_.erase” ss “”)
);;progn
);; if
(princ)
)