CAD Forums > CAD General

Rename a block with a common prefix - wildcard? and/or Replace Block

(1/3) > >>

tedg:
I know you can use wildcards in the "rename" dialog, but that doesn't work on the command line.
I want to rename a block in a bunch of drawings, but the block names vary but have the same prefix.
Specifically these are exported Revit title blocks to AutoCAD and I need to replace them with a proper AutoCAD title block.

When Revit exports blocks, it gives them specific names based on the sheet name, so in my case, the title block (block) names vary like:
(examples only): "TitleBlock - Titleblock Structural Notes"  and "TitleBlock - Titleblock Foundation Plan" etc
I want to rename and/or replace these blocks with a common AutoCAD created one.
The attributes aren't an issue, they are simply text on top of the title block and will remain, so it's just replacing one block with another.

I am trying to rename them something common and predictable so I can replace them with "insert oldblock=newblock" type of programming.


I looked into some other threads like THIS ONE and have looked at Lee Mac's "copy/rename" block routine, but this asks you to select the block.


Anyone have any ideas on how I can achieve this?


Thanks

mjfarrell:
I recall   -insert Block name= block name  should work for you....

ronjonp:
Maybe something like this:


--- Code - Auto/Visual Lisp: ---;; Assuming no dynamic blocks(defun _rename (newblock pattern / name)  (if (findfile newblock)    (vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))      (if (wcmatch (strcase (setq name (vla-get-name b))) (strcase pattern))        (progn (command ".-INSERT" (strcat name "=" newblock) '(0 0 0) nil)               (print (strcat name " redefined..."))        )      )    )  )  (princ))(_rename "C:\\Path\\newblock.dwg" "*titleblock*")*edit to fix variable missed

tedg:

--- Quote from: mjfarrell on October 28, 2015, 10:05:31 AM ---I recall   -insert Block name= block name  should work for you....

--- End quote ---
The problem is that these blocks names vary but with a common prefix, not wanting to find the exact block name but use a wild card.
This "-insert" command will not allow wildcards, and the rename command will not allow wild cards.


I tried to do something like:
"-insert TitleBlock*=c:\path\newTitleBlock" ... but "TitleBlock*" is an invalid block name.

tedg:

--- Quote from: ronjonp on October 28, 2015, 10:18:05 AM ---Maybe something like this:


--- Code - Auto/Visual Lisp: ---;; Assuming no dynamic blocks(defun _rename (newblock pattern / name)  (if (findfile newblock)    (vlax-for b   (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))      (if (wcmatch (strcase (setq name (vla-get-name b))) (strcase pattern))   (progn (command ".-INSERT" (strcat name "=" newblock) '(0 0 0) nil)          (print (strcat name " redefined..."))   )      )    )  )  (princ))(_rename "C:\\Path\\newblock.dwg" "*titleblock*")*edit to fix variable missed

--- End quote ---
Thanks Ronjonp, I'll poke around with this to see if I can use this, looks promising.
Thanks again.

Navigation

[0] Message Index

[#] Next page

Go to full version