Batch routine to replace blocks in multiple drawings

Batch routine to replace blocks in multiple drawings

Anonymous
Not applicable
5,380 Views
2 Replies
Message 1 of 3

Batch routine to replace blocks in multiple drawings

Anonymous
Not applicable

I have a large number of drawings 100+ with blocks that need replacing. So for example I need to change block 123 to block ABC in all drawings. Has anyone written a lisp routine to do something like this? Most of the routines I found look like they only redefined blocks that had the same name or would do multiple blocks in the same drawing. 

0 Likes
5,381 Views
2 Replies
Replies (2)
Message 2 of 3

marko_ribar
Advisor
Advisor

This came recently :

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-to-replace-block-with-dynamic...

 

Maybe if you save your block as separate DWG, then place it in SFSP and change routine with SCRIPT command to reflect DWG path and your block names, it should work no matter if block is dynamic or static...

 

HTH.

Regards, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 3

hencoop
Advisor
Advisor

I would use a script.

If you don't have a script writer you can use notepad just about as easily.

The key to any script is the command sequence, e.g. (numbers are line # references, do not include them):

(1).QSAVE

(2).OPEN

(3)<path><filename>

(4)-INSERT <original block name>=<new block name  (and path if not in the current folder or on your AutoCAD Support File Search Path)> 

(5)Yes

(6 & 6+1 thru n & n+1) Repeat (4) and (5) for each separate block name.

 

Save your command sequence in a text file with the extension ".scr"

 

Verify that the simple sequence works on the initial drawing.  Undo to your starting condition and make corrections if something went wrong.  The prompts in your text window show what went wrong if something does.  Once it works for the first drawing it will work for all drawings, unless they do not have one of the original blocks, then the "Yes" will not belong in the sequence; nevertheless, you can enter 'RESUME at the command line and the script will continue.

 

Once it is working, copy the sequence for each file you need to update and change the filenames to match each file.

 

A script writer should allow you to select the files you want and insert the command sequence you want to construct the batch script for all of your files.  I have an old one that may work for you.  It is free here: http://paracadd.com/bplot2k/bplot2k.htm Don't worry that it says it's for 2004-2013.  It works in 2019.  BTW, I just noticed that my web site says the lisp section was updated in 2007.  That should be 2017.  I don't look at it much at all.

bplot2k.jpg

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024