rcb007 Posted June 27, 2023 Posted June 27, 2023 I am trying to replace text inside an Autocad table. Using the Edit Find and Replace dialog, it works. But I have been trying to use other routines, however they all seem to only work with a MTEXT type and not the ACAD_Table type. https://www.theswamp.org/index.php?topic=5892.0 ;| 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 |; (defun txtfind (patt newpatt / count ss ent str txthgt match?) (vl-load-com) (vla-startundomark (vla-Get-ActiveDocument (vlax-Get-Acad-Object))) (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 str (cdr (assoc 1 ent))) (while (setq match? (vl-string-search patt str)) (setq str (vl-string-subst newpatt patt str)) (vla-put-textstring obj str) );while );progn );first condition ((= (cdr (assoc 0 ent)) "DIMENSION") (progn (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) );while );progn );second condition ((= (cdr (assoc 0 ent)) "MTEXT") (progn (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) );while );progn );third condition (t (progn (if (= (vla-get-hasattributes obj) :vlax-true) (progn (setq atts (vlax-invoke obj 'getattributes)) (foreach x atts (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) );while );for );progn );if );progn );last condition );cond );while );progn );if (vla-endundomark (vla-Get-ActiveDocument (vlax-Get-Acad-Object))) (princ "done....") (princ) );defun ;Example usage: ;(txtfind "badtext" "goodtext") I tried to add the ACAD_TABLE filter to the (ssget "x" '((0 . "TEXT. MTEXT,DIMENSION,INSERT,ACAD_TABLE)))), but no luck. Thanks for any help. Quote
devitg Posted June 27, 2023 Posted June 27, 2023 54 minutes ago, rcb007 said: I am trying to replace text inside an Autocad table. Using the Edit Find and Replace dialog, it works. But I have been trying to use other routines, however they all seem to only work with a MTEXT type and not the ACAD_Table type. https://www.theswamp.org/index.php?topic=5892.0 ;| 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 |; (defun txtfind (patt newpatt / count ss ent str txthgt match?) (vl-load-com) (vla-startundomark (vla-Get-ActiveDocument (vlax-Get-Acad-Object))) (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 str (cdr (assoc 1 ent))) (while (setq match? (vl-string-search patt str)) (setq str (vl-string-subst newpatt patt str)) (vla-put-textstring obj str) );while );progn );first condition ((= (cdr (assoc 0 ent)) "DIMENSION") (progn (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) );while );progn );second condition ((= (cdr (assoc 0 ent)) "MTEXT") (progn (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) );while );progn );third condition (t (progn (if (= (vla-get-hasattributes obj) :vlax-true) (progn (setq atts (vlax-invoke obj 'getattributes)) (foreach x atts (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) );while );for );progn );if );progn );last condition );cond );while );progn );if (vla-endundomark (vla-Get-ActiveDocument (vlax-Get-Acad-Object))) (princ "done....") (princ) );defun ;Example usage: ;(txtfind "badtext" "goodtext") I tried to add the ACAD_TABLE filter to the (ssget "x" '((0 . "TEXT. MTEXT,DIMENSION,INSERT,ACAD_TABLE)))), but no luck. Thanks for any help. @rcb007 Please upload sample.dwg Quote
rcb007 Posted June 27, 2023 Author Posted June 27, 2023 Hopefully this will help. Thank you again. Sample.dwg Quote
devitg Posted June 28, 2023 Posted June 28, 2023 18 hours ago, rcb007 said: Hopefully this will help. Thank you again. Sample.dwg 1.2 MB · 1 download @rcb007 Would it be the text to search at the same column table? please upload a real dwg sample. Quote
SLW210 Posted June 28, 2023 Posted June 28, 2023 Try this AutoLISP Solutions: Change Your Tables | Cadalyst Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.