View Full Version : Multiple block Rename
BCrouse
2006-08-01, 02:54 PM
Does anyone know of of lisp that would allow you to find and replace blocks names? Right when you want to rename a block you use the rename command to do that. This idea would allow you to find all blocks that has similar namse and replaces it with something different.
Example: you have 10 blocks with BK in the name. Now you want to change the names of the 10 blocks that has BK in it to CG.
Thank you,
brad
rkmcswain
2006-08-01, 03:20 PM
Give this vba code a shot.
Sub foo()
Dim item As AcadBlock
For Each item In ThisDrawing.Blocks
item.Name = Replace(item.Name, "BK", "CG")
Next item
End Sub
BCrouse
2006-08-01, 03:27 PM
Give this vba code a shot.
Sub foo()
Dim item As AcadBlock
For Each item In ThisDrawing.Blocks
item.Name = Replace(item.Name, "BK", "CG")
Next item
End Sub
What is the command to invoke it?
Use the VBARUN command to open the Macros Dialog Box to select FOO.
rkmcswain
2006-08-01, 03:43 PM
What is the command to invoke it?
In it's present form, "foo". But that was just provided as a sample. Rename as desired.
There are a couple of methods to run this.
1) Type in VBAMAN, create a new project, highlight that project and click the "Visual Basic Editor" button. Find that project in the Project Pane in the VBA editor, double click on "ThisDrawing". Paste the code in the edit box. Put your cursor somewhere in the code, and press F5. Done. (this doesn't save anything - one time use)
2). Repeat above, except click the save button, and save this code to a DVB file. In the future, use VBAMAN to load the DVB file, and VBARUN to run this code.
3) Many other ways to do things such as "autoload" this routine, run from a command line shortcut, run from a toolbar button, etc. Let me know your ultimate intentions.
BCrouse
2006-08-01, 04:29 PM
In it's present form, "foo". But that was just provided as a sample. Rename as desired.
There are a couple of methods to run this.
1) Type in VBAMAN, create a new project, highlight that project and click the "Visual Basic Editor" button. Find that project in the Project Pane in the VBA editor, double click on "ThisDrawing". Paste the code in the edit box. Put your cursor somewhere in the code, and press F5. Done. (this doesn't save anything - one time use)
2). Repeat above, except click the save button, and save this code to a DVB file. In the future, use VBAMAN to load the DVB file, and VBARUN to run this code.
3) Many other ways to do things such as "autoload" this routine, run from a command line shortcut, run from a toolbar button, etc. Let me know your ultimate intentions.
I like item number #3.
Thank you very much!
Brad
Or, do the same thing in lisp.....
(defun c:foo ()
(vlax-for blk (vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
)
(if (vl-string-search "BK" (strcase (vla-get-name blk)))
(vla-put-name blk (vl-string-subst "CG" "BK" (vla-get-name blk)))
)
)
(princ)
)
But I suspect that this isn't really what Brad wants......this only renames the block definitions (and, by default, the Inserts, too). What I think he wants is to rename the Block References to be a different block.......correct?
tyeelaw13
2006-08-08, 06:24 PM
You know you can also use wildcards in the RENAME command. So if you wanted to change every block that started wtih W2, you can type in W2* and use it in the rename to box as well. It will highlight and change every block that starts with W2* to the new name.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.