Saturday, November 21, 2009
Home   |   Search   |   About AUGI   |   My AUGI   |   Join Now

Go Back   AUGI Forums > AUGI Technical (English) > Programming > AutoLISP
 Welcome, Guest. 

Login

Join Now FAQ Members List Calendar Search Today's Posts Mark Forums Read

AutoLISP AutoLISP or Visual LISP, learn both here!

Reply
 
Thread Tools Display Modes
Old 2004-07-07, 08:47 PM   #1
hbisco
Active Member
 
Join Date: 2002-07
Location: Sycamore, IL USA
Posts: 68
hbisco is going the right wayhbisco is going the right wayhbisco is going the right wayhbisco is going the right wayhbisco is going the right way
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
hbisco is offline   Reply With Quote
Old 2004-07-07, 11:23 PM   #2
whdjr
I could stop if I wanted to
 
Join Date: 2003-05
Posts: 335
whdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of light
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?
__________________
Good Blockin'

Will DeLoach
AutoCad / ADT 2006

Last edited by whdjr : 2004-07-07 at 11:26 PM.
whdjr is offline   Reply With Quote
Old 2004-07-08, 12:38 AM   #3
hbisco
Active Member
 
Join Date: 2002-07
Location: Sycamore, IL USA
Posts: 68
hbisco is going the right wayhbisco is going the right wayhbisco is going the right wayhbisco is going the right wayhbisco is going the right way
Default

The text is dtext and we are using 2004, although i believe the drawings were originally created in R12 (maybe even R11).
hbisco is offline   Reply With Quote
Old 2004-07-12, 01:12 AM   #4
tuomo.jarvinen
Member
 
tuomo.jarvinen's Avatar
 
Join Date: 2001-10
Location: Jyväskylä, Finland
Posts: 12
tuomo.jarvinen is starting their journey
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...
tuomo.jarvinen is offline   Reply With Quote
Old 2004-07-12, 04:26 PM   #5
whdjr
I could stop if I wanted to
 
Join Date: 2003-05
Posts: 335
whdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of light
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 ;
}
__________________
Good Blockin'

Will DeLoach
AutoCad / ADT 2006
whdjr is offline   Reply With Quote
Reply


Go Back   AUGI Forums > AUGI Technical (English) > Programming > AutoLISP

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How are companies using the Sheet Set Manager ? nhugley AutoCAD Sheet Set Manager 47 2008-08-01 08:07 PM
Labelling Rotated Drawings sinc Land Desktop - General 1 2004-06-26 07:34 PM
Find and Replace Text mark_a Revit Architecture "Original" Wish List (Archived) 4 2004-06-01 04:04 AM


All times are GMT +1. The time now is 01:09 PM.