Jump to content

Recommended Posts

Posted

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.

Posted
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  

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...