I want to be able to run a script project-wide that finds and replaces specific text, but the find command requires a dialog box to operate, which can't be used in a script file. Is there another way to accomplish this?
Hi, I had the same problem. My solution was to download a lisp file called "mfind" and then use that in a script. I've attached it.
I actually wanted to do something slightly different than you. I had a bunch of schematics that were the same, but with different info/tags/etc inside. So I made a template of the schematic with every variable having a unique string. The script basically started with the template open, did a find and replace for all of the variables, did a "save as" to the correct file name, opened the same template again and repeated.
(Additionally, I had all the info in Excel, and used an Excel macro to generate the Acad script.)
Anyway, in your case, you could adapt my method so that instead of opening the same template after each find/replace, you would open the next file in your list of files to work on. Also-- I did this back in AutoCAD 2009, I think.
Here is what my script file looked like:
(load "C:/.../mfind/mfind") (CommandMFind "XDWG" "402-EL-761" T T T T T nil nil) (CommandMFind "XDWTAG" "402-FM-48-M1" T T T T T nil nil) (CommandMFind "XTAG" "402-FM-48-M1" T T T T T nil nil) (CommandMFind "XNAME" "MECANISMO CELDA DE FLOTACION SEGUNDA LIMPIA DE ZINC" T T T T T nil nil) (CommandMFind "XHP" "30" T T T T T nil nil) (CommandMFind "XDEV" "402FM48M1" T T T T T nil nil) SAVEAS "P:/.../working/ 402EL761.dwg" SAVEAS "P:/.../working/402EL761.dwg" close OPEN "P:/.../template1-3single.dwg" (load "C:/.../mfind/mfind") (CommandMFind "XDWG" "402-EL-762" T T T T T nil nil) (CommandMFind "XDWTAG" "402-FM-49-M1" T T T T T nil nil) ETC ETC ETC
I can't remember why I had to do SAVEAS twice, once with a space in front of the file name. Seems pretty stupid. It might not be necessary. But it worked, and I don't remembering it creating two files. Also, I took out the file paths and replaced them with "..." for viewing and privacy purposes.
BUT, this way, while it works, is cumbersome and prone to bugs. I hope someone else replies with a better way.
What kind of text are you trying to replace? Is it an attribute, XData, text entity, or something else? If you can give more specific requirements, there may be possible solutions.
Regards,
Lee
Thank you very much!
I would like this code (mfind) to be able to replace texts inside blocks (not as attributes). How to add replacement inside blocks?
@OlgaGan wrote:
Thank you very much!
I would like this code (mfind) to be able to replace texts inside blocks (not as attributes). How to add replacement inside blocks?
https://www.lee-mac.com/bfind.html