Jump to content

Find & Replace Text


drewd1508

Recommended Posts

  • 2 months later...
  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • drewd1508

    6

  • rkmcswain

    4

  • dbroada

    3

  • abzn

    3

That script by Terry Cadd works great, except for in Multileaders & Tables. Any chane someone can help me out by telling me how to add multileaders and tables into the script?

 

Also does not work with Annotative text, which all my text is - :(

Cheers

Link to comment
Share on other sites

  • 2 months later...

To find and replace text in AutoCAD 2000 I use a LISP routine I found, mfind. I also changed my registry to add a "ASC Submittal" to my right click context menu in Windows Explorer. I just change the submittal.scr file accordingly. You will have to modify the .reg file for your computer, but it should give you enough of an idea on how to do it. I also have a script to batch plot.

 

Since I run multiple versions of AutoCAD on my computer I had to change the registry for all of the versions to use the AutoCAD 2000 program from the right click menu. Also, selecting more than 5 files at a time will sometimes lockup my computer. If you are smart I would love it if you could improve on my idea!

mfind.zip

Right Click Script.zip

Link to comment
Share on other sites

  • 1 month later...
Hi There,

Would like some help on a small problem that i have. I am trying to do a batch 'Find and Replace' exercise on a batch of autocad drgs. ie i need a program of some sort that will open a drawing, find a series of text strings and replace them with another series text strings and then save and close the drg.

 

old text string could be say 537:00089 and new text string would be 537D:0032. There could be dozens/hundreds of numbers within a drg.

 

Any ideas?

 

I add this option to this thread... just found it today.. untested by me... but it's published in cadalyst.. so I guess it works.

 

http://www.cadalyst.com/cad/autocad/hot-tip-harry-tips-our-readers-april-2005-5143?print=1

It seems to work for text, mtext and attributes also. and nice dialog box features... I think.

Replace Text In Dwgs.DCL

Replace Text In Dwgs.LSP

Link to comment
Share on other sites

My method above works well in AutoCAD 2000, not sure of newer versions. It is not easy to setup, so you may want to look into some third party software such as Hurricane for AutoCAD.

Link to comment
Share on other sites

You can find a LISP program Here that will run through multiple drawings and run a find and replace program.

 

The Batch program was designed by Tony Tanzillo and the find and replace function is REPSTRING... With help from LeeMac, I was able to put the two together in that thread and create a batch find and replace lsp.

Link to comment
Share on other sites

  • 10 years later...
On 8/8/2007 at 2:26 AM, Terry Cadd said:

Here is a function that I wrote to be used in programs, but it can be run on the command line using the following syntax:

(FindReplaceAll "537:00089" "537D:0032")

Use it with care, because it does exactly what it's named.

Terry Cadd

 

Quote

;-------------------------------------------------------------------------------
; FindReplaceAll - Changes Text, Mtext, Dimensions and Attribute Block entities
; that have a Find$ string with a Replace$ string.
; Arguments: 2
;   Find$ = Phrase string to find
;   Replace$ = Phrase to replace it with
; Syntax: (FindReplaceAll "old string" "new string")
; Returns: Updates Text, Mtext, Dimension and Attribute Block entities
;-------------------------------------------------------------------------------
(defun FindReplaceAll (Find$ Replace$ / BlkEntList@ BlkEntName^ BlkEntType$ Cnt#
 DimEntList@ DimEntName^ DimEntType$ EntList@ EntName^ EntType$ FindReplace:
 Mid$ Mid2$ NewText$ Num# Replace$ SS& Text$)
 ;-----------------------------------------------------------------------------
 ; FindReplace: - Returns Str$ with Find$ changed to Replace$
 ; Arguments: 3
 ;   Str$ = Text string
 ;   Find$ = Phrase string to find
 ;   Replace$ = Phrase to replace Find$ with
 ; Returns: Returns Str$ with Find$ changed to Replace$
 ;-----------------------------------------------------------------------------
 (defun FindReplace: (Str$ Find$ Replace$ / Cnt# FindLen# Loop Mid$ NewStr$ ReplaceLen#)
   (setq Loop t Cnt# 1 NewStr$ Str$ FindLen# (strlen Find$) ReplaceLen# (strlen Replace$))
   (while Loop
     (setq Mid$ (substr NewStr$ Cnt# FindLen#))
     (if (= Mid$ Find$)
       (setq NewStr$ (strcat (substr NewStr$ 1 (1- Cnt#)) Replace$ (substr NewStr$ (+ Cnt# FindLen#)))
             Cnt# (+ Cnt# ReplaceLen#)
       );setq
       (setq Cnt# (1+ Cnt#))
     );if
     (if (= Mid$ "") (setq Loop nil))
   );while
   NewStr$
 );defun FindReplace:
 ;-----------------------------------------------------------------------------
 ; Start of Main function
 ;-----------------------------------------------------------------------------
 (if (and (= (type Find$) 'STR)(= (type Replace$) 'STR)(/= Find$ ""))
   (progn
     (if (setq SS& (ssget "x" (list '(-4 . "<AND")'(-4 . "<OR")'(0 . "TEXT")'(0 . "MTEXT")'(0 . "DIMENSION")'(0 . "INSERT")'(-4 . "OR>")(cons 410 (getvar "CTAB"))'(-4 . "AND>"))))
       (progn
         (command "UNDO" "BEGIN")
         (setq Cnt# 0)
         (repeat (sslength SS&)
           (setq EntName^ (ssname SS& Cnt#)
                 EntList@ (entget EntName^)
                 EntType$ (cdr (assoc 0 EntList@))
                 Text$ (cdr (assoc 1 EntList@))
           );setq
           (if (= EntType$ "INSERT")
             (if (assoc 66 EntList@)
               (progn
                 (while (/= (cdr (assoc 0 EntList@)) "SEQEND")
                   (setq EntList@ (entget EntName^))
                   (if (= (cdr (assoc 0 EntList@)) "ATTRIB")
                     (progn
                       (setq Text$ (cdr (assoc 1 EntList@)))
                       (if (wcmatch Text$ (strcat "*" Find$ "*"))
                         (progn
                           (setq ReplaceWith$ (FindReplace: Text$ Find$ Replace$))
                           (entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@))
                           (entupd EntName^)
                         );progn
                       );if
                     );progn
                   );if
                   (setq EntName^ (entnext EntName^))
                 );while
               );progn
             );if
             (if (wcmatch Text$ (strcat "*" Find$ "*"))
               (progn
                 (setq ReplaceWith$ (FindReplace: Text$ Find$ Replace$))
                 (entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@))
                 (entupd EntName^)
               );progn
             );if
           );if
           (setq Cnt# (1+ Cnt#))
         );repeat
         (command "UNDO" "END")
       );progn
     );if
   );progn
 );if
 (princ)
);defun FindReplaceAll

IF WE WANT RUN THIS FOR SELECTED AREA INSTEAD OF ALL DRAWING, HOW WE CAN MODIFIED IT??

(INDEED THE FIRST DRAG MUSE AND SELECT OBJECTS )

 

 

 

 

Edited by hosyn
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...