Autocad Find and Replace Multiple Drawings

#1

Default Find and Replace text in multiple drawings

We have a folder with about 30 drawings that we need to go in and find and replace several different lines of text. I am a neophyte with creating lisp routines, but is there a way to create a routine which could go in and find and replace text in multiple drawings within a folder?

thanks,

Hugh


#2

Default Re: Find and Replace text in multiple drawings

YES IT CAN BE DONE, BUT SOME SPECIFICS ARE NEEDED. IS THE TEXT DTEXT OR MTEXT?
WHAT VERSION OF AUTOCAD ARE YOU USING?
Last edited by whdjr; 2004-07-07 at 09:26 PM.

#3

Default Re: Find and Replace text in multiple drawings

The text is dtext and we are using 2004, although i believe the drawings were originally created in R12 (maybe even R11).

#4

Default Re: Find and Replace text in multiple drawings

I was asked a while ago to write a lisp to do something almost similar: to change attribute values in titleblocks in a bunch of drawings (same value to all). I figured out that the lisp must write a script to do the job. I quess this has been done many times but following is what I have came up with:

(WARNING: NOVICE PROGRAMMING)

;THIS LISP WRITES A SCRIPT TO CHANGE ATTRIBUTE VALUES IN A BUNCH OF DRAWINGS
;bgae = "Batch Global Attribute Edit"
;2:02 12.7.2004 TJ

;Assumption 1: Doslib available
;Assumption 2: Expresstools gatte available

;Usage:
;Move all the drawings in one folder
;Open one of them
;Load and run bgae.lsp (this lisp)
;Run the script (batch.scr, created in the same folder)

(defun c:bgae (/ dwgnames titleblock blockname attrib-name new-attrib-val scriptname dwg-in-turn)

;creating a list of drawings:

(setq dwgnames (dos_dir (strcat (getvar "dwgprefix") "*.dwg")))

;getting the information: blockname, attribute name and the new value:

(setq titleblock (entsel "Please choose a block: "))
(setq blockname (cdr (assoc 2 (entget (car titleblock)))))
(command "undo" "m")
(command "explode" titleblock)
(setq attrib-name (cdr (assoc 2 (entget (car (entsel "Please choose an attribute: "))))))
(command "undo" "b")
(setq new-attrib-val (getstring "New value for attribute? "))

;writing the script:

(setq scriptname (open (strcat (getvar "dwgprefix") "batch.scr") "w"))
(write-line "isavebak 0" scriptname)
(write-line "close n" scriptname)

(progn
(repeat (length dwgnames)
(setq dwg-in-turn (car dwgnames))
(setq dwgnames (cdr dwgnames))

(write-line (strcat "open " (getvar "dwgprefix") dwg-in-turn) scriptname)
(write-line (strcat "gatte b " blockname " " attrib-name " " new-attrib-val) scriptname)
(write-line (strcat "Y qsave close") scriptname)

) T)

(close scriptname)
)

ScriptPro from Migration Assistant could also be helpful in this kind of tasks.

Hopely somebody more skillfull comments this subject...


#5

Default Re: Find and Replace text in multiple drawings

Hugh,

I think I've failed you. I'm so close but just can't close it. The code I have below gives you a dialog box to select a file (single selection only). Once you select the file and click open it reloads the dialog box to select another file and continues this process until you click cancel. Then it continues with the rest of the routine. This process can be changed to select all the dwg's in a folder if you need that instead.

I tried to emulate the ACAD find & replace, but did a bad job. I put in 3 options to search by:
1. Matching the whole word only.
2. Matching case only.
3. Matching both whole word and case.

To say the least this was not easy. I quickly determined that I didn't have the time nor the skills to effectively construct this for you. So I am putting my work here in hopes that some other brave souls will take pity on me and help you out and instruct me on how to do this (if even possible). My code currently only works for option #2 (case). I am too busy right now to work on option #1. The only way I could think of to implement option #1 was to look at the ascii character values of the text string and compare those to the space value, I just don't have that much time right now. Sorry.

The other problem that I had wasn't so big, kind of little. I can't get the program to save the changes back to the file. I'm doing something wrong ang\d its not updating the textstring properly. Once again I'm am truely sorry for getting your hopes up and then failing you miserably.

Hope this helps in some small way,

Code:

                  (vl-load-com)  (defun *error* (msg)   (princ "\nError: ")   (princ msg)   (princ)   (if (and dbxdoc (not (vlax-object-released-p dbxdoc))) 	(vlax-release-object dbxdoc)   )   (gc)   (princ) )   (defun fandr (txtobj)   (vl-string-subst news olds (vla-get-textstring txtobj)) )   (defun findandreplacetext (document)   (vlax-for item (vla-get-modelspace document) 	(cond ((not (= (vla-get-ObjectName item) "AcDbText"))) 		  ;((and whole case)())  This matches whole word and case 		  ;(whole ())			This matches whole word only	    (case (fandr item));   This matches case only		      (T (fandr item));	  This matches neither whole word nor case 	)   ) )   (defun c:tfar (/ file files dcl_id dbxdoc of olds news whole case)   (setq file "")   (while (setq file   (getfiled "Select a file to replace text in" file "dwg" 128)   ) 	(setq files (cons file files))   )   (cond ((not files) (princ "No files were selected."))  ((not (setq dcl_id (load_dialog "textreplace.dcl")))   (princ "Unable to load dialog box.")  )  ((not (new_dialog "textreplace" dcl_id))   (princ "Could not load (textreplace.dcl) dialog box.")  )  ((not 	(and (not (mode_tile "eb1" 2))   (action_tile "eb1" "(setq olds (get_tile \"eb1\"))")   (action_tile "eb2" "(setq news (get_tile \"eb2\"))")   (action_tile "tog1" "(setq whole $value)")   (action_tile "tog2" "(setq case $value)")   (action_tile "cancel" "(done_dialog)")   (action_tile "ok" "(done_dialog)")   (if (and (= (start_dialog) 1) 	(> (strlen olds) 0) 	(> (strlen news) 0) 	  ) 	(not (unload_dialog dcl_id)) 	(unload_dialog dcl_id)   ) 	)   )   (princ "Function Cancelled by User.")  )  ((not (setq dbxdoc (vla-GetInterfaceObject 		(vlax-get-acad-object) 		"ObjectDBX.AxDbDocument.16" 	  ) 	   )   )   (princ "Unable to load ObjectDBX.")  )  (T   (foreach f (reverse files) 	(setq of (vl-catch-all-apply 		'(lambda () 	(vlax-invoke-method dbxdoc 'open f) 		 ) 	  ) 	) 	(if (vl-catch-all-error-p of) 	  (*error* (vl-catch-all-error-message of)) 	  (progn 		(findandreplacetext dbxdoc) 		(vla-saveas dbxdoc f) 	  ) 	)   )  )   )   (if (and dbxdoc (not (vlax-object-released-p dbxdoc))) 	(vlax-release-object dbxdoc)   )   (gc)   (princ) )

Code:

                  //dcl_settings : default_dcl_settings {audit_level = 3; } textreplace : dialog {   label = "Replace Text" ;   : row {   : column { 	: edit_box { 	  key = "eb1"; 	  label = "Find text string:"; 	  edit_width = 20; 	  is_default = true; 	} 	: edit_box { 	  key = "eb2"; 	  label = "Replace with:"; 	  edit_width = 20; 	}   }   : boxed_column { 	: toggle { 	  key = "tog1"; 	  label = "Find whole words only"; 	  } 	: toggle { 	  key = "tog2"; 	  label = "Match case"; 	  } 	} 	}   ok_cancel ; }

#6

eugene_k is offline

Member


Default Re: Find and Replace text in multiple drawings

I believe those people capable of doing this level of lisp programing could do much better job by creating a universal code for batch processing various lisp files on multiple drawings. Instead of solving just one problem of text replacement, we couls just start this batch engine program, select the files to be processed and then select a lisp to run! It could be lisp for text replacement or for anything else - you name it. This is where the real power is. Maybe Autodesk should provide this sort of engine instead of its ScriptPro...
There is no good tool availbale at the moment. If anybody ever find something good, please let me know!

#7

jsowinski is offline

Member


Default Re: Find and Replace text in multiple drawings

Here is a routine that came from Cadalyst Tips (author - Andrzej Gumula). This is a great tool that works fast. If you encounter an error while running you will want to check the part of the code that looks for (getvar "AcadVer"). "ObjectDBX.AxDbDocument.17" You may have to update the number in the lisp to the version of AutoCAD you're using.

#8

Default Re: Find and Replace text in multiple drawings


#9

raghu.sahaja is offline

Member


Default Re: Find and Replace text in multiple drawings

Quote Originally Posted by jsowinski View Post

Here is a routine that came from Cadalyst Tips (author - Andrzej Gumula). This is a great tool that works fast. If you encounter an error while running you will want to check the part of the code that looks for (getvar "AcadVer"). "ObjectDBX.AxDbDocument.17" You may have to update the number in the lisp to the version of AutoCAD you're using.

Hi, what command i have to type in command line

#10

Dave Jones is offline

I could stop if I wanted to


Default Re: Find and Replace text in multiple drawings

Quote Originally Posted by raghu.sahaja View Post

Hi, what command i have to type in command line

command: Reid

grossmanhimened.blogspot.com

Source: https://forums.augi.com/showthread.php?5580-Find-and-Replace-text-in-multiple-drawings

0 Response to "Autocad Find and Replace Multiple Drawings"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel