Big thanks to Tim and Ron for helping me out with this.
Ron got me squared away with this update and all is well again.
So, what we used to do with this lisp was to write a script that just ran this routine over and over again for each string we wanted to change. With Ron's update, we just throw what used to be in the script down at the bottom of the code and run the lisp.
Again, many thanks to you both!
(defun txtfind (patt newpatt / _replacetext e el n obj ss str)
;| Routine to find specified text and replace with new text. Works on Text,
Mtext, Attributes and Dimension text overrides.
WARNING: it will change all occurances of a pattern with the new text.
Such as: if "test" "contest" "testing" are all valid text entries in the
drawing, running this: (txtfind "test" "newtest") will change
the original text to "newtest" "connewtest" "newtesting", but for the
original intent of this routine that was not a problem. Modifications
may be made to force matching of whole word only.
by: Jeff Mishler Sept. 2003
10.16.2012 Modified by RJP to prevent infinite loop when source search includes all or part of replace pattern
Created more refined filter
ie.
(txtfind "AI1" "FAI1")
(txtfind "AI2" "FAI2")
|;
(defun _replacetext (new old textstring / i out tmp)
(cond ((vl-string-search old textstring)
(setq tmp textstring)
(setq out "")
(while (setq i (vl-string-search old tmp))
(setq out (strcat out (vl-string-subst new old (substr tmp 1 (+ i (strlen old))))))
(setq tmp (substr tmp (1+ (+ i (strlen old)))))
)
(if (zerop (strlen tmp))
out
(strcat out tmp)
)
)
(textstring)
)
)
(vl-load-com)
;; More refined filter
(if (setq ss (ssget "_X"
(list '(-4 . "<OR")
'(-4 . "<AND")
;; *text that only has part of the search string
'
(0 . "MTEXT,TEXT")
(cons 1 (strcat "*" patt "*"))
'(-4 . "AND>")
'(-4 . "<AND")
;; Attributed blocks
'
(0 . "INSERT")
'(66 . 1)
'(-4 . "AND>")
;; Dimension DUH :)
'
(-4 . "<AND")
'(0 . "DIMENSION")
'(-4 . "AND>")
'(-4 . "OR>")
)
)
)
(progn
;;(vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(setq n -1)
(while (setq e (ssname ss (setq n (1+ n))))
(setq el (entget e))
(setq obj (vlax-ename->vla-object e))
(cond ((wcmatch (cdr (assoc 0 el)) "TEXT,MTEXT")
(setq str (cdr (assoc 1 el)))
(vla-put-textstring obj (_replacetext newpatt patt str))
)
((= (cdr (assoc 0 el)) "DIMENSION")
(and (wcmatch (strcase (setq str (cdr (assoc 1 el)))) (strcat "*" patt "*"))
(vla-put-textoverride obj (_replacetext newpatt patt str))
)
)
(t
(foreach x (vlax-invoke obj 'getattributes)
(and (wcmatch (strcase (setq str (vla-get-textstring x))) (strcat "*" patt "*"))
(vla-put-textstring x (_replacetext newpatt patt str))
)
)
)
)
)
;;(vla-endundomark adoc)
)
(princ "\nNo Text entities found!")
)
(princ)
)
(txtfind "AI1" "FAI1")
(txtfind "AI2" "FAI2")
(txtfind "AI3" "FAI3")
(txtfind "AI4" "FAI4")
(txtfind "AO1" "FAO1")
(txtfind "AO2" "FAO2")
(txtfind "AO3" "FAO3")
(txtfind "AO4" "FAO4")
(txtfind "DI1" "FDI1")
(txtfind "DI2" "FDI2")
(txtfind "DI3" "FDI3")
(txtfind "DI4" "FDI4")
(txtfind "DO1" "FDO1")
(txtfind "DO2" "FDO2")
(txtfind "DO3" "FDO3")
(txtfind "DO4" "FDO4")