Code Red > AutoLISP (Vanilla / Visual)

Command line Find

<< < (2/8) > >>

Mark:
Yep, with autolisp or vba it is.

You should be about ready to handle that one now, right? You are in Stig's class aren't you?
:)

Sitra:

--- Quote from: Mark Thomas ---
You should be about ready to handle that one now, right?
--- End quote ---


Unfortunately no...:cry:


--- Quote from: Mark Thomas --- You are in Stig's class aren't you?
--- End quote ---


Yes, sir. But, I am so far behind it is not even funny...
 :roll:

Jeff_M:
Hi Conrad,
Here's a function I put together a while back that you could easily use in a new lisp to do what you want.

--- Code: ---
;| 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 (vla-getattributes obj))
(foreach x (vlax-safearray->list (vlax-variant-value 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)
  );defun

--- End code ---

Make sure this loads first in acaddoc.lsp, then add your lisp after it. Something like this:

--- Code: ---
(txtfind "badtext" "goodtext")

--- End code ---

Sitra:
Thanks Jeff, I will give it a try... :D

M-dub:

--- Quote from: Jeff_M on April 04, 2005, 07:04:37 PM ---Here's a function I put together a while back...

--- End quote ---

Love this one.  Comes in handy, it does!  :-D

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version