Here is a quick fix that seems to work on the issue with dtext. Added the same fix to all items that the program works on.
(defun txtfind (patt newpatt / count ss ent str txthgt match? cnt slen)
;| 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
|;
(vl-load-com)
(vla-startundomark (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
(setq slen (strlen newpatt))
(setq ss (ssget "X" '((0 . "TEXT,MTEXT,DIMENSION,INSERT"))))
(if (not ss)
(princ "\nNo Text entities found!")
(progn
(setq count -1)
(while (< (setq count (1+ count))(sslength ss))
(setq ent (entget (ssname ss count))
obj (vlax-ename->vla-object (cdr (car ent))))
(cond
((= (cdr (assoc 0 ent)) "TEXT")
(progn
(setq cnt 0)
(setq str (cdr (assoc 1 ent)))
(while (setq match? (vl-string-search patt str cnt))
(setq str (vl-string-subst newpatt patt str))
(vla-put-textstring obj str)
(setq cnt (+ slen match?))
);while
);progn
);first condition
((= (cdr (assoc 0 ent)) "DIMENSION")
(progn
(setq cnt 0)
(setq str (cdr (assoc 1 ent)))
(while (setq match? (vl-string-search patt str))
(setq str (vl-string-subst newpatt patt str))
(vla-put-textoverride obj str)
(setq cnt (+ slen match?))
);while
);progn
);second condition
((= (cdr (assoc 0 ent)) "MTEXT")
(progn
(setq cnt 0)
(setq str (vla-get-textstring obj))
(while (setq match? (vl-string-search patt str))
(setq str (vl-string-subst newpatt patt str))
(vla-put-textstring obj str)
(setq cnt (+ slen match?))
);while
);progn
);third condition
(t
(foreach x (vlax-invoke obj 'GetAttributes)
(setq cnt 0)
(setq str (vla-get-textstring x))
(while (setq match? (vl-string-search patt str))
(setq str (vl-string-subst newpatt patt str))
(vla-put-textstring x str)
(setq cnt (+ slen match?))
);while
);for
);last condition
);cond
);while
);progn
);if
(vla-endundomark (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
(princ)
)