Find / Replace Text - Multiple pairs

Find / Replace Text - Multiple pairs

don_scribner
Contributor Contributor
470 Views
5 Replies
Message 1 of 6

Find / Replace Text - Multiple pairs

don_scribner
Contributor
Contributor

Hey guys,

 

I work for a company that is constantly changing part numbers.  That means that a drawing set done a month ago is now incorrect.  Any part number could reside in  . . . . 30 locations throughout the package and at present, there are about 30 numbers to change.  Does anyone know have a lisp that I can steal and doctor to make this work a) Easier and   b) more consistent for my fellow drafters?   

Ideally, you would start the lisp and it would go down a list and change:

 

121345    to  1098722

789987   to  1762845

etc, etc

 

It needs to be able to reach inside blocks at well as free-range text.  

As I revise my templates, I use the FIND command. but it is work intensive and I am prone to lousy typing. Also I have tried LeeMac's routine, but it simply would not do anything. 

 

My hope is that one of folks that is smarter than me has already run into this issue . . . .

 

Thanks in advance!

 

Don

0 Likes
Accepted solutions (1)
471 Views
5 Replies
Replies (5)
Message 2 of 6

hak_vz
Advisor
Advisor

What kind of Autocad entities you have in your drawings (inside block or as free objects) i.e. text, mtext, leaders, tables.... block attributes, fields ? Are this object (part numbers) according to drafting standard hold on specific layer.  Attach sample drawing if you can.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 6

don_scribner
Contributor
Contributor

Mtext, leaders and possibly text.  I just included a file with three blocks that are indicative of what I am up against.  Thanks for taking a look at it.  Ive done simple lisps for years but you guys would take one look at them and laugh yourselves to death. 

0 Likes
Message 4 of 6

hak_vz
Advisor
Advisor
Accepted solution

Lets start with following code. Task is not simple since there are various combinations of text in play. Code is barely tested so take your time and check it on different drawings. I'm not sure if it will work for all potential cases since in your drawings since you may have blocks inside blocks inside blocks an all other weird combinations. That's why I personally prefer GROUPS over Blocks where system variable PICKSTYLE define if objects are editable or not. But that is another story. Anyway ,try this code  and report your findings. You should change

 

(setq partnumbers 
		(list
			(list "300284/300285" "5555555/6666666")
			(list "302454/306258" "aaaaa/bbbbb")
			(list "311111" "CCCCC")
			(list "411111" "DDDDD")
		)
	)

 

 

 

(defun c:change_part_numbers ( / partnumbers i ss ent)
	;part numbers list (old new)
	(setq partnumbers 
		(list
			(list "300284/300285" "5555555/6666666")
			(list "302454/306258" "aaaaa/bbbbb")
			(list "311111" "CCCCC")
			(list "411111" "DDDDD")
			
			
			
		)
	)
	(defun ReplaceBlockText ( old new / _StringSubst doc ) (vl-load-com)
	 ;; © Lee Mac 2011

	 (defun _StringSubst ( new old str / i l ) (setq i 0 l (strlen new))
	   (while
		 (and
		   (< i (strlen str))
		   (setq i (vl-string-search old str i))
		   (setq str (vl-string-subst new old str i) i (+ i l))
		 )
	   )
	   str
	 )

	 (vlax-for block
	   (vla-get-blocks
		 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
	   )
	   (if
		 (and
		   (eq :vlax-false (vla-get-isXref block))
		   (eq :vlax-false (vla-get-isLayout block))
		 )
		 (vlax-for obj block
		   (if (wcmatch (vla-get-objectname obj) "AcDb*Text")
			 (vla-put-TextString obj (_StringSubst new old (vla-get-TextString obj)))
		   )
		 )
	   )
	 )
	 (vla-regen doc acActiveViewport)
	 (princ)
	)

	(foreach entry partnumbers
		(setq ss (ssget "_X" (list (cons 0 "*TEXT")(cons 1 (strcat "*"(car entry)"*")))))
		(cond 
			((and ss)
				(setq i -1)
				(while (< (setq i (1+ i)) (sslength ss))
					(setq ent (entget (ssname ss i)))
					(setq newstr (vl-string-subst (cadr entry) (car entry) (cdr (assoc 1 ent))))
					(setq ent (subst (cons 1 newstr) (assoc 1 ent) ent))
					(entmod ent)
				)
			)
			(T nil)
		)
		(ReplaceBlockText (car entry) (cadr entry))
	)

	(princ "\nDone")
	(princ)
)

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 6

MrJSmith
Advocate
Advocate
I'd recommend Lee Mac's BFIND command. You can choose what to replace, where to replace, replace across multiple drawings, etc. It is an extremely powerful and flexible program.

http://www.lee-mac.com/bfind.html

0 Likes
Message 6 of 6

don_scribner
Contributor
Contributor

DUDE!  PERFECT!  THANK YOU!

 

This is exactly what I needed.  I'll add this to the toolbars and with one simple click and all is right with the world. And we stop getting dinged by the checkers!