I found some coding on another site that is supposed to change one block name to another block name, and it appears that it will do many block names all at once based on a list. I can't get it to work and my drawings have around 100 blocks on them each which need to be renamed, plus I have hundreds of drawings that would need to be batch renamed so I don't have to open each file individually.
The end goal is to replace Block A with Block B where the difference between the blocks is attributes, colors and names, but done on many drawings in a folder with many blocks per drawing.
My idea is to run a batch file that will rename all of the blocks from old name to new name, then run a batch file to replace Block A with Block B using a list of blocks within a script. I have a master file containing the blocks that I want the script to look for, then replace them all with the new blocks. I don't know if there is an easier way to do this because my current drawings have blocks named Block A to Block Z, and the new blocks are named Block 1 to Block 26.
This is the rename that I found:
Code:
;;function to rename a block.
;;if old block exists, and new block doesn't exist, the old block is simply renamed.
;;if old block exists, it does nothing
;;if old block it alerts 'Block not found'.
(defun renblock (ol nl / ss i ent )
(cond ((and (tblsearch "block" ol) (not (tblsearch "block" nl)))
(command "._rename" "block" ol nl)
)
((and (tblsearch "block" ol)(tblsearch "block" nl))
(setq ss (ssget "x" (list (cons 2 ol))))
(setq i -1)
(repeat (sslength ss)
(setq ent (entget (ssname ss (setq i (1+ i))))
ent (subst (cons 2 nl) (cons 2 (cdr (assoc 2 ent))) ent)
)
(entmod ent)
)
)
((not (tblsearch "block" ol))
(prompt (strcat "\nBlock " ol " not found. "))
)
)
(princ)
)
;;example
(defun c:test ()
(renblock "old block1" "Renamed1")
(renblock "old block2" "Renamed2")
(renblock "old block3" "Renamed3")
)