AutoCAD Electrical Forum
Welcome to Autodesk’s AutoCAD Electrical Forums. Share your knowledge, ask questions, and explore popular AutoCAD Electrical topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Find and replace script

6 REPLIES 6
Reply
Message 1 of 7
deason
10993 Views, 6 Replies

Find and replace script

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?

6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: deason

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.

Message 3 of 7
leeholl
in reply to: deason

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

 

Message 4 of 7
deason
in reply to: leeholl

I found a solution. http://www.lee-mac.com/bfind.html

Seems to work as desired so far...

Message 5 of 7
OlgaGan
in reply to: Anonymous

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?

Message 6 of 7
pendean
in reply to: OlgaGan


@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

pendean_0-1710515458565.png

 

Message 7 of 7
OlgaGan
in reply to: pendean

Thank you!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost