Jump to content

Batch Find & Replace Text


Lee Mac

Recommended Posts

  • 3 months later...

Dear Lee Mac

 

Thanks for the sharing the program. I can see your hard work, as I am now trying to develop a routine for multiple Find and Replace using excel VBA (just started). I was trying to replace the Mtext that is in Japanese language with the equivalent English text. Japanese language fonts are in Unicode unlike the English fonts that are in Ansi encoding.

 

Meanwhile, I got this error when trying to make a multiple find and replace. I used the version2 lisp file from - http://lee-mac.com/bfind.html

------------------------------------

Command: bfind

Working, Please Wait....

** Error Processing Drawing: Sample.dwg **

** Error Detail: Win32: No mapping for the Unicode character exists in the

target multi-byte code page **Regenerating model.

Command:

>

>

Command:

------------------------------------

 

One of the reason is that my system locale is set to Japanese. So, I changed that to English. Still was not able to make the find and replace. I get this error even when I find to replace even a simple English text.

------------------------------------

Command: bfind

Select Object:

Working, Please Wait....Regenerating model.

Command:

>

>

Command:

------------------------------------

For example, when I click this button >> for Find_what and select this text "プレート取付ケ状態" in the drawing, i get the following "{\W0.844962;プレート取付ケ状態}" in the Find what text box. I am not sure what this "\W0.844962;" is, and may be it is related to Japanese font (Unicode font). I am getting some sort of text whenever I select a Japanese text.

When I use the AutoCAd inbuild Find function to Find and Replace single text, it is working without any issue. I am not sure why I am not able to make any replacement using your program. Try to guide me when you are free.

 

When working on your program, I find some other things. Don't feel that I am asking for too much. You once said in one of your reply that this program would not have come to this level if not for the users comments. Based on that I am giving the following comments and suggestions though not all are required for me at this moment. I will be very happy to test your beta version of the program.

 

Bug

1) The program allows me to add 2 different "Replace with" for the same "Find what"

--------------------------

Find what Replace with

Sample aaa

Sample bbb

--------------------------

This should not be allowed. Some sort of checking the previous entries should be done before adding a new set of text

 

2) I am also able to add the same text for "Find what" and "Repalce with". This shall be avoided with some check.

--------------------------

Find what Replace with

Sample New Text

Sample New Text

--------------------------

 

Some other improvement

 

1) Saving in DXF format: I checked this thread: http://forums.augi.com/showthread.php?t=132331

----------------------------

So I guess that even inserting something like this within your program wouldn't work?

(vla-get-saveastype

(vla-get-opensave

(vla-get-preferences

(vlax-get-acad-object)

SaveAsType

acSaveAsType enum; read-write

ac2007_dwg

AutoCAD 2007 DWG (*.dwg)

 

That is changing the save settings in the Options for the Active Document, and hence will not affect the ObjectDBX Document.

----------------------------

I am not able to understand the meaning of your reply. If it is possible to save in older version for the current drawing, can you provide that when the "Current drawing" option is selected. That is a combo box should appear where the users can select the version they can save the file for the current drawing and it shall remember that.

 

2) If search only option is clicked, then it should deactivate the Replace window. I was trying the find and replace for few time with the search only option checked by mistake.

 

3) When I save a list, it shall give the location where it is saving the file just below the "Save as" dialog box.

 

4) When batch replacement is made, you may add some text like "Saving the file in (current version)"

 

5) When "Current Directory" is clicked, then it should erase the previous folder selected through the "Directory" option. Otherwise there will be confusion for the user, on the folder for replacement.

 

6) When "All open Drawings" is clicked, the number of open drawing shall be displayed. This will be caution for when the user is unaware of the number of opened drawings.

 

7) The length of Directory display shall be increased as it is showing partially. May be you need to provide multiline text to show the full path. I think you should use the word "Drawing folder" instead of "Drawing Directory" in the frame as Folder is the common usage. You may prefer the change the name of button from "Directory" to "Browse". The function of the button is Browse and that is the common usage.

 

8) You may change the name of "Current drawing" to "Active drawing" (I am telling this from vba syntax and not sure of the LISP syntax).

 

Regards

Chandru

Link to comment
Share on other sites

I know you had an issue with MText shifting but I have a case of the first line being repeated and I cant figure out why.The attached drawing has the text I am trying to replace. I want to replace the #BR1 - #BR6 with other values but when I try to do this I get the first line repeated in every instance of this type of text. Am I doing something wrong with the program or is there a way I can fix this?

 

Thanks for your help.

 

BFIND_Issue.dwg

Link to comment
Share on other sites

Hi Chandru,

 

Please see the replies to your comments below:

 

I got this error when trying to make a multiple find and replace. I used the version2 lisp file from - http://lee-mac.com/bfind.html

------------------------------------

Command: bfind

Working, Please Wait....

** Error Processing Drawing: Sample.dwg **

** Error Detail: Win32: No mapping for the Unicode character exists in the

target multi-byte code page **Regenerating model.

Command:

>

>

Command:

------------------------------------

 

I have developed the program to work with ASCII character encoding and haven't incorporated support for Unicode characters.

 

One of the reason is that my system locale is set to Japanese. So, I changed that to English. Still was not able to make the find and replace. I get this error even when I find to replace even a simple English text.

------------------------------------

Command: bfind

Select Object:

Working, Please Wait....Regenerating model.

Command:

>

>

Command:

------------------------------------

 

This isn't an error, the program is just indicating that no replacements have been made in the drawing, most likely because the 'Find' string could not be found in any of the selected objects to be searched.

 

For example, when I click this button >> for Find_what and select this text "プレート取付ケ状態" in the drawing, i get the following "{\W0.844962;プレート取付ケ状態}" in the Find what text box. I am not sure what this "\W0.844962;" is, and may be it is related to Japanese font (Unicode font). I am getting some sort of text whenever I select a Japanese text.

 

The "{\W0.844962;" is an MText formatting code (not related to the Unicode characters), these formatting codes are present in the text string whenever formatting is applied to objects using MText (MText/MLeaders/Dimensions etc.).

 

In the next version I shall implement code to remove the formatting codes when displaying selected text in the dialog.

 

When I use the AutoCAd inbuild Find function to Find and Replace single text, it is working without any issue. I am not sure why I am not able to make any replacement using your program.

 

Because my program does not use the inbuilt AutoCAD Find function.

 

Bug

1) The program allows me to add 2 different "Replace with" for the same "Find what"

--------------------------

Find what Replace with

Sample aaa

Sample bbb

--------------------------

This should not be allowed. Some sort of checking the previous entries should be done before adding a new set of text

 

Well spotted, I shall fix this in the next version.

 

2) I am also able to add the same text for "Find what" and "Repalce with". This shall be avoided with some check.

--------------------------

Find what Replace with

Sample New Text

Sample New Text

--------------------------

 

Same as above.

 

1) Saving in DXF format: I checked this thread: http://forums.augi.com/showthread.php?t=132331

----------------------------

So I guess that even inserting something like this within your program wouldn't work?

(vla-get-saveastype

(vla-get-opensave

(vla-get-preferences

(vlax-get-acad-object)

SaveAsType

acSaveAsType enum; read-write

ac2007_dwg

AutoCAD 2007 DWG (*.dwg)

 

That is changing the save settings in the Options for the Active Document, and hence will not affect the ObjectDBX Document.

----------------------------

I am not able to understand the meaning of your reply. If it is possible to save in older version for the current drawing, can you provide that when the "Current drawing" option is selected. That is a combo box should appear where the users can select the version they can save the file for the current drawing and it shall remember that.

 

ObjectDBX only will permit saving to the native version (i.e. the highest version available in the application in which the program is being used). Changing the SaveAsType property will have no effect on the ObjectDBX document, since this property only changes the default save version in the Options Dialog.

 

I do not intend to add extra options that are only available for some selected drawings.

 

2) If search only option is clicked, then it should deactivate the Replace window. I was trying the find and replace for few time with the search only option checked by mistake.

 

No it shouldn't. Otherwise the user cannot add 'replace' strings and so cannot see the 'preview' of the replacement operation in the CSV report, which defeats the point of having this functionality.

 

3) When I save a list, it shall give the location where it is saving the file just below the "Save as" dialog box.

 

I feel the program should handle the data storage, and the user should use the dialog interface to access the stored lists, not the inner workings of the program.

 

However, I may add an 'Edit' button to a future version so that the saved searches file may be edited manually.

 

4) When batch replacement is made, you may add some text like "Saving the file in (current version)"

 

Thank you for the suggestion.

 

5) When "Current Directory" is clicked, then it should erase the previous folder selected through the "Directory" option. Otherwise there will be confusion for the user, on the folder for replacement.

 

The directory should be 'greyed out', indicating that only the current drawing will be processed; but perhaps erasing the text could be clearer.

 

6) When "All open Drawings" is clicked, the number of open drawing shall be displayed. This will be caution for when the user is unaware of the number of opened drawings.

 

I considered adding a line beneath the toggles in the Drawing Directory panel to display the number of drawings to be processed for the selected directory / selected toggle settings; however, if the user unexpectedly sets 'Include Subdirectories' for a high-level root directory, the program will needlessly scour many directories just to display the number of drawings.

 

7) The length of Directory display shall be increased as it is showing partially. May be you need to provide multiline text to show the full path.

 

A difficult one since the directory could be very long indeed for different users - but I agree that the display could be increased.

 

I think you should use the word "Drawing folder" instead of "Drawing Directory" in the frame as Folder is the common usage. You may prefer the change the name of button from "Directory" to "Browse". The function of the button is Browse and that is the common usage.

 

I agree that the button should be 'Browse', but I intend to keep the term: 'Directory'.

 

You may change the name of "Current drawing" to "Active drawing" (I am telling this from vba syntax and not sure of the LISP syntax).

 

I feel that 'Current Drawing' is more applicable to the majority of non-programmer users that will more likely be using the program.

 

Thank you for your detailed feedback Chandru, it is greatly appreciated, I now have many ideas and bug fixes to implement in the next version.

 

Thanks

 

Lee

Link to comment
Share on other sites

Hello,

I've implemented BFind Ver 2-0 due to I find it useful judging from description. In fact I have to change only title block in every single of my 130 drawings. I wanted to prepare such list in Excel and have stored as text. I cannot find the file mentioned - Acad gives me answer (nil) also for (findfile "LMAC_BFind_SavedSearches_V2-0.txt"). Please assist.

Thanks in advance.

The find/replace string saved searches are stored in the file in this location:

 

type at the command line:

(findfile "LMAC_BFind_SavedSearches.txt")

 

As for the Find Only: tick the 'Search Only' box.

Link to comment
Share on other sites

Hello,

I've implemented BFind Ver 2-0 due to I find it useful judging from description. In fact I have to change only title block in every single of my 130 drawings. I wanted to prepare such list in Excel and have stored as text. I cannot find the file mentioned - Acad gives me answer (nil) also for (findfile "LMAC_BFind_SavedSearches_V2-0.txt"). Please assist.

Thanks in advance.

 

The file will only exist if you have already saved some searches. Run the program, add a few search/replace strings, and click Save. After saving, cancel the main dialog and attempt to find the file.

 

Lee

Link to comment
Share on other sites

Lee, thank you for prompt answer. Still no result - I cannot find that *.txt file however lists are stored somewhere because I can read them under BFind dialog display. Additional thing is that AutoCAD 2008 is installed on C:\. I don't have "write" permission to that disc. Some other configuration files are placed on network drive (e.g. Acad.pat) to which i also have no write permission. Only custom configuration files I have on my D:\ local drive which I can modify. Maybe that might be a reason. Nevertheless I've searched "My computer" so network drives inclusive for any *BFind*.txt files with no results - strange to me and a pity. Please assist.

_Atilla_

The file will only exist if you have already saved some searches. Run the program, add a few search/replace strings, and click Save. After saving, cancel the main dialog and attempt to find the file.

 

Lee

Link to comment
Share on other sites

Lee,

that solves everything - I couldn't find it due to it's hidden folder. Anyway - problem solved - thank's a million.

Regards,

_Atilla_

Have a look in the directory stored by the ROAMABLEROOTPREFIX System Variable.
Link to comment
Share on other sites

Lee,

that solves everything - I couldn't find it due to it's hidden folder. Anyway - problem solved - thank's a million.

Regards,

_Atilla_

 

You're very welcome _Atilla_ :)

 

As an aside: My initial intentions were to have the program handle the loading/saving of the search/replace strings, with the user manipulating the content solely through the dialog interface. But in the next version I may add an 'Edit' button to the Load dialog to open the .txt file in which the search/replace strings are stored for manual editing.

 

Lee

Link to comment
Share on other sites

  • 1 month later...

Hi Lee,

 

the lisp works great but I have found one minor issue and I don't know if it is linked with doing a heavy load of batch replacing but I am finding that the text that gets replaced is getting shifted to the right. I thought maybe the justification was getting changed since it looks like the result of left justifying a centered text but after checking I still find my text is set to centered.

 

Have you noticed this at all?

Link to comment
Share on other sites

Hi taka,

 

Unfortuately this is a known bug when modifying text strings with ObjectDBX that ADesk haven't fixed. I have included a subfunction in the program to attempt to counter the shift in position, but this may not work in all cases.

 

Lee

Link to comment
Share on other sites

  • 1 month later...
I Think i found a new bug. if you search for character "{" or "}" it will not find it. It's Odd. :?

 

You're right, it won't find curly braces - this appears to be a result of how the replacement engine in the program handles MText formatting codes - not an easy one to fix I'm afraid.

Link to comment
Share on other sites

Thanks for Reply

Actually i'm using your perfect program for another purpose :)

I have many files with shx font and want to use your program to convert them to TTF. unfortunately some original characters are "{" or "}" and Bfind ignore them. I am building a new character map by using "LMAC_BFind_SavedSearches.txt". I'll be Appreciate if you help me to go through this problem.

Link to comment
Share on other sites

Hi, Lee

I've find that errors with using BFindV2-0.lsp with the condition of chinese version XP system & Autocad2010 English version.

"

Command: bfind

Working, Please Wait....

** Error Processing Drawing: 62-100-D-04.dwg **

** Error Detail: Win32: No mapping for the Unicode character exists in the

target multi-byte code page **.

"

It seems like activex automation errors.

Thanks.

Xia

Link to comment
Share on other sites

  • 3 weeks later...

Hello

There are ideas for improving your program's functionality Bfind

1) Make a choice of the filter Layer for replacement text

2) Make a selection file with the table replace text in txt format or Excel

Can you make these changes to your program?

 

Thank you.

 

P.S. Sorry for my English :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...