Jump to content

Batch Find & Replace Text


Lee Mac

Recommended Posts

Batch Find & Replace Text

 

This program uses ObjectDBX to perform multiple text replacements on the current drawing or a complete directory (and subdirectories) of drawings. The program has the ability to search Text, MText, Block Attributes, Multileader Text, Table Cell Text and Dimension Override Text.

 

The user may replace multiple search strings, and load & save lists of search strings for future use, saving time in program data entry.

 

Users may perform a complete Find & Replace operation, or merely search for potential replacements using the 'Search Only' option. Following a search operation, a report is displayed informing the user of the replacements which would be performed should the user proceed with the replacement. The report also displays the object containing the text to be replaced, along with the entity handle of such object, and the drawing filename in which the object resides.

 

The program provides the user additional refinement options, as displayed in the Options Dialog. This enables the user to control which objects are searched, whether locked layers are included in the replacement, search item case-sensitivity and whether the search item must appear as a complete word to be replaced.

 

The generation of a report following a text replacement may also be controlled within the Options Dialog (the report will always be created following a search operation).

 

Help and examples can be found in the Code Header:

Dialog Preview:

 

BFindV2-0-1.png BFindV2-0-2.png

 

Options Dialog:

 

BFindV2-0-3.png

 

Function Syntax: BFind

 

;;-------------------------=={  Batch Find & Replace  }==------------------------;;
;;                                                                               ;;
;;  Will Find and Replace multiple strings entered by the user within Text,      ;;
;;  MText, Block Attributes, MLeader Text, Table Text and Dimensions within the  ;;
;;  current drawing, all currently open drawings and/or a directory              ;;
;;  (and subdirectories) of drawings.                                            ;;
;;                                                                               ;;
;;  If the 'Block Definitions' option is selected, all instances of the          ;;
;;  aforementioned text objects residing within block definitions are included   ;;
;;  in the search domain.                                                        ;;
;;                                                                               ;;
;;  Furthermore the user may choose which objects to search, whether the find    ;;
;;  string is case sensitive, and whether to restrict the search to whole words  ;;
;;  only.                                                                        ;;
;;-------------------------------------------------------------------------------;;
;;                                                                               ;;
;;  FUNCTION SYNTAX:  BFind                                                      ;;
;;                                                                               ;;
;;  Notes:                                                                       ;;
;;  ---------                                                                    ;;
;;  As expected, the known bug with ObjectDBX arises with regards to attribute   ;;
;;  alignment following modification. A sub-function has been included in an     ;;
;;  attempt to correct the change in position, however, a slight shift in        ;;
;;  position may be noticed. The attribute is realigned when the block is moved  ;;
;;  manually.                                                                    ;;
;;                                                                               ;;
;;  Also, when using the Batch Find and Replace, drawing thumbnails are lost     ;;
;;  upon saving with ObjectDBX. These return when the drawing is saved manually. ;;
;;                                                                               ;;
;;-------------------------------------------------------------------------------;;
;;                                                                               ;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com                          ;;
;;                                                                               ;;
;;-------------------------------------------------------------------------------;;
;;                                                                               ;;
;;  With additional thanks to Joe Burke for his tremendous help towards using    ;;
;;  Regular Expressions to eliminate the problem of MText formatting codes when  ;;
;;  performing replacements.                                                     ;;
;;                                                                               ;;
;;-------------------------------------------------------------------------------;;
;;  Version:                                                                     ;;
;;                                                                               ;;
;;  1.0:  24/05/2010  -  First Release                                           ;;
;;-------------------------------------------------------------------------------;;
;;  1.1:  26/05/2010  -  Added Options Button.                                   ;;
;;                    -  Updated String Replacement functions to allow for case  ;;
;;                       sensitivity options.                                    ;;
;;                    -  Upgraded StringRep function to allow replacement string ;;
;;                       to contain find string.                                 ;;
;;                    -  Fixed bug causing an unsaved drawing to be saved.       ;;
;;-------------------------------------------------------------------------------;;
;;  1.2:  29/05/2010  -  Added ability to perform multiple replacements.         ;;
;;-------------------------------------------------------------------------------;;
;;  1.3:  31/05/2010  -  Added ability to edit find and replace entry by         ;;
;;                       double-clicking.                                        ;;
;;                    -  Added 'Table Text' object to Options Dialog.            ;;
;;                    -  Added 'Find Whole Words Only' option to Options Dialog. ;;
;;                    -  Redesigned Options Dialog to accommodate new toggles,   ;;
;;                       added mnemonics.                                        ;;
;;-------------------------------------------------------------------------------;;
;;  1.4:  27/04/2010  -  Replaced 'StringRep' function with functions utilising  ;;
;;                       Regular Expressions to allow for MText formatting.      ;;
;;-------------------------------------------------------------------------------;;
;;  1.5:  29/09/2010  -  Reformatted code.                                       ;;
;;                    -  Drawings only saved if a replacement is made.           ;;
;;-------------------------------------------------------------------------------;;
;;  1.6:  03/10/2010  -  Added pick buttons to select text for Find/Replace      ;;
;;                       strings.                                                ;;
;;                    -  Added 'Match Case' option                               ;;
;;                    -  Added 'Find Whole Words Only' option                    ;;
;;-------------------------------------------------------------------------------;;
;;  1.7:  05/10/2010  -  Added 'Search Only' option in which the program will    ;;
;;                       search for multiple strings within the current drawing  ;;
;;                       and/or a directory (and subdirectories) of drawings,    ;;
;;                       subsequently producing a report detailing the number    ;;
;;                       of occurrences of each string and list of possible      ;;
;;                       changes should a replacement be performed.              ;;
;;                    -  Added error trap to drawing processing loop to prevent  ;;
;;                       crash should one drawing error.                         ;;
;;                    -  Added delay to DCL creation.                            ;;
;;-------------------------------------------------------------------------------;;
;;  1.8:  08/10/2010  -  Added Load & Save buttons to allow a set of search      ;;
;;                       items to be loaded and saved.                           ;;
;;-------------------------------------------------------------------------------;;
;;  1.9:  09/10/2010  -  Fixed bug involving capital 'S' being removed from      ;;
;;                       textstring during stacking formatting code removal.     ;;
;;                    -  Added code to allow 'special' characters to be used in  ;;
;;                       Find string.                                            ;;
;;-------------------------------------------------------------------------------;;
;;  2.0:  22/07/2011  -  Majority of program rewritten and reformatted to        ;;
;;                       include the following enhancements:                     ;;
;;                    -  Fixed tab stops in dialog to allow the user to use the  ;;
;;                       tab key to navigate between edit boxes.                 ;;
;;                    -  Added 'Where to Search' panel to allow the user to      ;;
;;                       restrict the search to Modelspace, Layout space or Both.;;
;;                    -  Added 'Block Definitions' to list of objects to search  ;;
;;                       to allow users to search text objects in blocks.        ;;
;;                    -  Added 'Current Directory' toggle to allow the user to   ;;
;;                       quickly select the current working directory to be      ;;
;;                       processed.                                              ;;
;;                    -  Added ability to add items to find/replace list by      ;;
;;                       pressing Enter from within either edit box.             ;;
;;                    -  Added ability to press Enter after entering Save        ;;
;;                       Reference without needing to click the OK button.       ;;
;;                    -  Added ability to press Enter after editing entry        ;;
;;                       without needing to click the OK button.                 ;;
;;                    -  Changed format of Saved Searches file for easier        ;;
;;                       manual editing.                                         ;;
;;                    -  Added ability to process 'All Open Drawings'.           ;;
;;-------------------------------------------------------------------------------;;

 

A full description can be found here.

 

Disclaimer: BFind.lsp is not entirely bug-free, as demonstrated by the information contained herein: I would hence advise against its usage in cases where heavily formatted MText is involved. However, it should, in most cases, perform successfully.

 

When replacements are made, drawings will be saved in native format (i.e. if run in AutoCAD2010, will be saved as 2010 drawing).

BFindV2-0.lsp

Edited by Lee Mac
  • Like 1
Link to comment
Share on other sites

I think they call that a "teaser" Lee. Don't be playing with us! LOL

 

Indeed I am - I have seen so many questions about a Batch Find and Replace, I thought I'd give it a shot. :)

Link to comment
Share on other sites

Congratulations

 

Thanks Asos,

 

I'm pleased to have the basic program runnning, I have a few more ideas I may add in future to make the program function similar to the AutoCAD Find command.

 

I'm glad you like it,

 

Lee

Link to comment
Share on other sites

Yes, as I say in the first post, at this point, the replacement string cannot contain the find string, as the program would loop endlessly, as there would always be something to replace.

 

EDIT: The next version will solve this problem :)

Link to comment
Share on other sites

Dear Sir,

U R Really Genius......

Thx for u r all program basically all freeware & unprotected.

i study all program & learn more & more

Thx Lee Mac

Link to comment
Share on other sites

You're welcome, I enjoy writing them :)

 

Wow, this is indeed a neat, super, great, love-it program !!

 

I have some ideas on how to add to this general idea and bury the other "batch" programs here and elsewhere. I can put 'em here or PM.

S

Link to comment
Share on other sites

Wow, this is indeed a neat, super, great, love-it program !!

 

I have some ideas on how to add to this general idea and bury the other "batch" programs here and elsewhere. I can put 'em here or PM.

S

 

Certainly, I welcome ideas :)

 

My current ideas are to add an Options button, which would include toggles for Case Sensitivity, and which objects to search for the text.

 

Lee

Link to comment
Share on other sites

Hi Lee

 

another option that I think would be great is if you could have a text file with multiple user definable find and replace strings which the program would load and then run.

 

Something like this:

 

R, Ridge

E, Eaves

C, Conc

etc.

 

The find string separated with a comma or tab from the replace string.

 

Ta

L

Link to comment
Share on other sites

That would be fantastic.

Would the dialog then save them to a file so that they can be re-loaded/persist for another day.

 

One other thing whilst your here, I'm not sure if you saw my post over at the swamp

http://www.theswamp.org/index.php?topic=29124.msg381508#msg381508

i'm Pad over there. The post seemed to get lost pretty quickly, which is why I'm mentioning it once more.

 

Its about adding the x, y and z insertion points as an export option to the excellent GAE.

 

thanks again

Link to comment
Share on other sites

Ah, yes I forgot to reply to your post - what with the influx of subsequent posts that emerged in that thread...

 

I think it is possible to add the block insertion to the list of results, it would have to be at the end of each row of attribute values. But it would certainly be a lot of work, so I shall have to see if I have the time in the future. :)

 

Lee

Link to comment
Share on other sites

Would the dialog then save them to a file so that they can be re-loaded/persist for another day.

 

Yes, I normally use a small cfg file to store the settings for my programs :)

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...