Jump to content

Batch Find & Replace Text


Lee Mac

Recommended Posts

You've probably seen the discussion I'm having with Joe over at theSwamp regarding MText formatting codes - I'm not planning to remove MText formatting codes completely - rather dissect the text, make replacements and then put the formatting back together.

 

Users know the risk of a Batch find and replace, I'm just providing an option for those who want to use it (that's probably not going to be you).

 

Lee

 

 

Yeah, I've been loosely following it and I hope you can pull it off. It's a really cool concept and you've put together some really nice code/interface for it.

 

I hope you are correct, but I feel that a good amount just load the program and start editing drawings. No, I won't use it (unless you add a search and report only function), but I'm sure something like this can be useful to others. The thing about it is, even if I automate replacing the text on 10-15 drawings, I'd still feel compelled to open and check, just to make sure everything went accordingly.

I commend you for your efforts and will continue following it. :)

 

I hope you don't interpret this as an attack on you. It's really nice; I just hope everyone who uses it truly comprehends the risks involved in such an intrusive program.

Link to comment
Share on other sites

I would hope that users are aware of such dangers of a batch find and replace program - and if they are not then: Use this program at your own risk! :D

 

Thanks for the compliments - I just wish I had more time to work on it in between studying...

Link to comment
Share on other sites

nice code mr lee but if i have many number and i would like to search in number between 1.20-1.50 is that possible

 

Not currently - the function doesn't have wildcard matching as yet, but only partial/whole word matching.

 

Lee

Link to comment
Share on other sites

This is a great routine! Thanks!

Question: It ignores locked layers which is great but sometimes folks here forget to lock the proper layers. Is there a place in the code where I can add to the locked layer list? (my layer that I want to lock is called Attributes).

Link to comment
Share on other sites

Thanks David, I'm glad you like it.

 

There isn't currently a facility to add to the locked layers list - just the option to ignore them all.

 

I'm currently in the process of upgrading the code for this program, as it is flawed in a big way when it comes to MText with nested formatting - which I hope to resolve in the near future.

 

Lee

Link to comment
Share on other sites

Yes, here:

 

...
                    (vlax-for lay (vla-get-Layers oDoc)
                      (if (eq :vlax-true (vla-get-Lock lay))
                        (progn
                          (vla-put-lock lay :vlax-false)
                          (setq Locked       (cons lay Locked)
                                LockedLayers (cons (strcase (vla-get-name lay)) LockedLayers)))))                     

(or (vl-position "ATTRIBUTES" LockedLayers)
   (setq LockedLayers (cons "ATTRIBUTES" LockedLayers)))

                    (vlax-for lay (vla-get-Layouts oDoc)
...

Link to comment
Share on other sites

I'm just waiting on a 'Search' only option.:wink:

 

True, as you probably know though, time is short with exams, and I want to get the Mtext formatting fixed first...

Link to comment
Share on other sites

True, as you probably know though, time is short with exams, and I want to get the Mtext formatting fixed first...

 

Oh yes, I totally understand.

Link to comment
Share on other sites

The program will replace text strings within multiple drawings in a directory (and subdirectories). The program will search Text, MText, Dimension Text, Leaders, MLeaders, and Block Attributes.

 

Help can be found in the Code Header:

Preview:

 

BFindV1-3.png

 

Editing an Entry:

 

EditEntryV1-3.png

 

Options Dialog:

 

OptionsV1-3.png

 

Function Syntax: BFind

 

;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;;;
;;;ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,¤º°`°º¤;;;
;;                                                                               ;;
;;                                                                               ;;
;;                       --=={  Batch Find & Replace  }==--                      ;;
;;                                                                               ;;
;;  Will Find and Replace strings entered by the user within Text, MText, Block  ;;
;;  Attributes, MLeader Text, Table Text and Dimensions within the current       ;;
;;  drawing and/or a directory (and subdirectories) of drawings.                 ;;
;;                                                                               ;;
;;  The user can choose which objects to search, whether the find string is      ;;
;;  case sensitive, and whether to search for whole words only, i.e. strings     ;;
;;  that match the Find String exactly in length.                                ;;
;;                                                                               ;;
;;  Example:   Find  ~  AutoCAD  =>  Replace With  ~  CAD                        ;;
;;                                                                               ;;
;;  With 'Match Case' ON:   AutoCAD  =>  CAD                                     ;;
;;                                                                               ;;
;;  With 'Match Case' OFF:  AutoCAD  =>  CAD                                     ;;
;;                          AUTOCAD  =>  CAD                                     ;;
;;                          AuToCaD  =>  CAD                                     ;;
;;                                                                               ;;
;;                                                                               ;;
;;  The user can also choose to 'Ignore Locked Layers', with this option set,    ;;
;;  all objects on Locked Layers are not searched for the Find String, else all  ;;
;;  objects are searched.                                                        ;;
;;                                                                               ;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  FUNCTION SYNTAX:  BFind                                                      ;;
;;                                                                               ;;
;;  Notes:-                                                                      ;;
;;  ---------                                                                    ;;
;;  As usual the known bug with ObjectDBX arises when it comes to attribute      ;;
;;  alignment after modification. A sub-function has been included to try to     ;;
;;  allow for the shift in position, however it is not 100% foolproof, and a     ;;
;;  slight shift in position may be noticed. The attribute is realigned when the ;;
;;  block is moved manually.                                                     ;;
;;                                                                               ;;
;;  As expected, when using the Batch Find and Replace, drawing thumbnails are   ;;
;;  lost upon saving with ObjectDBX. These return when the drawing is saved      ;;
;;  manually.                                                                    ;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  AUTHOR:                                                                      ;;
;;                                                                               ;;
;;  Copyright © Lee McDonnell, March 2010. All Rights Reserved.                  ;;
;;                                                                               ;;
;;      { Contact: Lee Mac @ TheSwamp.org, CADTutor.net }                        ;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  VERSION:                                                                     ;;
;;                                                                               ;;
;;  ø 1.0   ~¤~    24th March 2010   ~¤~                                         ;;
;;                                                                               ;;
;;  º First Release                                                              ;;
;;...............................................................................;;
;;  ø 1.1   ~¤~    26th March 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   ~¤~    29th March 2010   ~¤~                                         ;;
;;                                                                               ;;
;;  º Added ability to perform multiple replacements.                            ;;
;;...............................................................................;;
;;  ø 1.3   ~¤~    31st March 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.     ;;
;;...............................................................................;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;;;
;;;ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,¤º°`°º¤;;;

 

--=={ Code Updated to Version 1.3 }==--

 

Good job, looks great, but cant the same thing be done natively in Autocad with the FIND command?

 

xp0jz8.jpg

 

I'm looking for a procedure that lists all available text inside a drawing and lets you replace on the fly with no searching for specific strings.

Link to comment
Share on other sites

Good job, looks great, but cant the same thing be done natively in Autocad with the FIND command?

 

Not for multiple drawings at the same time I don't think...

Link to comment
Share on other sites

I don't think the FIND can replace multiple find and replace strings, or can it?

 

Lee, I think there is a bug with the 'match whole words only' option.

It doesn't seem to recognise a space as a break between words.

 

CBF -> C/B

 

CBF 1.3 should change to C/B 1.3

but instead it remains unchanged

 

bfind version 1.3.

 

Cheers

P

Link to comment
Share on other sites

Thanks for that Pad,

 

I'm currently working on a newer String Replace function that will replace the main engine in this program, but its having the time... :(

Link to comment
Share on other sites

You are correct.

 

Thank goodness for that - that would have been a lot of code down the drain otherwise... :)

 

that's always a problem in this day and age!

there's no rush though, take it easy..

P

 

Sure, this is only a hobby anyway... after all: Exams > LISP :)

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