Author Topic: Batch Text Find and Replace  (Read 1837 times)

0 Members and 1 Guest are viewing this topic.

AQucsaiJr

  • Guest
Batch Text Find and Replace
« on: November 02, 2009, 04:07:39 PM »
I found a thread that has a LISP program written by CAB that seems to be exactly what I want, but I have a couple issues with it and I am not code litterate enough to change what I need done...
The thread in question.http://www.theswamp.org/index.php?topic=14703.msg177823#msg177823

-I am getting an error after it has been run that will not allow any version of ACAD earlier than the one the LISP is run on to open any of the files.
-I want to create a use interface menu for the user to be able to give the text they want to replace and the text they want to replace that text with. I can not figure out the variables to change and because of this I can't figure out how to add more too it. I want to be able to search for multiple different lines of text to replace.
- Also.. has anyone figured out how to change the text within a block for this routine?
Thanks for your help.
« Last Edit: November 02, 2009, 04:24:57 PM by AQucsaiJr »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Batch Text Find and Replace
« Reply #1 on: November 02, 2009, 05:07:30 PM »
-I am getting an error after it has been run that will not allow any version of ACAD earlier than the one the LISP is run on to open any of the files.
This may be because it just issues the save as command ( through code, not really the command ).  Maybe if you change the default version of the save command, then it will save to a different format.

-I want to create a use interface menu for the user to be able to give the text they want to replace and the text they want to replace that text with. I can not figure out the variables to change and because of this I can't figure out how to add more too it. I want to be able to search for multiple different lines of text to replace.
Here is how to call the code, and you can see how to add multiple string replacements ( in red ).
Code: [Select]
(defun c:TextReplace ()
  ;;  Add flag values
  ;;  flag 1 = ModelSpace Only
  ;;       2 = PaperSpace Only
  ;;       4 = reserved
  ;;       8 = Include Attributed Blocks  * Not Operational
  ;;
  ;;  text to replace ("OldString" "NewString")
  (TextReplaceDBX 3 ; both Model & Paper Space
[color=red]    '(("OldText" "NewString")
      ("Test 012807.1" "NewString")
     )
  )[/color]
  (princ)
)

- Also.. has anyone figured out how to change the text within a block for this routine?
Thanks for your help.
This wouldn't be hard, but take some time, as you would have to step through each block definition, and see if they contain text, and then if they match one of the test strings.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

AQucsaiJr

  • Guest
Re: Batch Text Find and Replace
« Reply #2 on: November 03, 2009, 08:01:03 AM »
Well I use EZ Script Pro and a script I wrote now to do this so it is worth it to me to use this type of function as it would reduce the time it takes per drawing down significantly.  I will have to play with it a little and see what I can come up with.

AQucsaiJr

  • Guest
Re: Batch Text Find and Replace
« Reply #3 on: November 03, 2009, 08:32:49 AM »
Is this part supposed to take care of the Attributes?

Code: [Select]
;|((and (> (logand flag 8) 0)
                  (eq oType "AcDbBlockReference")
                  (eq (vla-get-hasattributes item) :vlax-true)
             )
             (foreach for-item (get_atts item)
               (swaptext obj lst)
             )
            )|;

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Batch Text Find and Replace
« Reply #4 on: November 03, 2009, 11:03:24 AM »
I would think so, but I haven't look at the two subs that are used in that portion.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.