How to find and replace text strings with no dialogs?
How to find and replace text strings with no dialogs?
(OP)
How to find and replace text strings with no dialogs? I wish to run a scipt if possible? Or does anyone know of a lsp that I can add my own find and replace values to?





RE: How to find and replace text strings with no dialogs?
RE: How to find and replace text strings with no dialogs?
try www.homescript.com
can even find English text and replace with Japanese equivalent
RE: How to find and replace text strings with no dialogs?
;
"CT" Change text. Correct spelling errors
;
(DEFUN chgterr (s)
(if (/= s "Function cancelled") ; If an error (such as CTRL-C) occurs
(princ (strcat "\nError: " s)) ; while this command is active...
)
(setq p nil) ; Free selection set
(setq *error* olderr) ; Restore old *error* handler
(princ)
)
;
(DEFUN C:CT (/ p l n e os as ns st s nsl osl sl si chf chm olderr) ; Correct spelling errors
(setq olderr *error* ; Initialize variables
*error* chgterr
chm 0)
(setq p (ssget)) ; Select objects
(if p (progn ; If any objects selected
(while (= 0 (setq osl (strlen (setq os (getstring t "\nOld string: ")))))
(princ "Null input invalid")
)
(setq nsl (strlen (setq ns (getstring t "\nNew string: "))))
(setq l 0 n (sslength p))
(while (< l n) ; For each selected object...
(if (= "TEXT" ; Look for TEXT entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(setq l (1+ l))
)
))
(princ "Changed ") ; Print total lines changed
(princ chm)
(princ " text lines.")
(terpri)
(setq *error* olderr) ; Restore old *error* handler
(princ)
)
RE: How to find and replace text strings with no dialogs?
"CT" runs it.
Of course, load it first !!!
In the lisp, look for the DEFUN C: and what comes after is the command that AutoCAD would recognize.
RE: How to find and replace text strings with no dialogs?
Vladimir Michl, Xanadu, www.xanadu.cz
RE: How to find and replace text strings with no dialogs?
RE: How to find and replace text strings with no dialogs?
Does help anyone with my issue - just seems I can't explanin myself for what i really want.
RE: How to find and replace text strings with no dialogs?
CadDraftee,
What are your criteria for changing the
text/attributes. Are the changes the same
for a batch of drawings. Do you have a sample
of the drawing showing the old/new text and/or
attributes. You don't want dialogs, so how do
you intend to make the changes known to the
routine...command line inputs?? It seems that
the info you have provided are inadequate to
get a decent reply from this forum.
RE: How to find and replace text strings with no dialogs?
RE: How to find and replace text strings with no dialogs?
"So I know that every occurance of F-123 is now going to
F0123 and all occuances of F-506 will be F0106."
Here's your routine:
;;;No error checking
;;;11-17-2003 CopyRight (C) 2005 L Estember
;;;Not for Resale or Mass Distribution,
;;;CopyRight (C) Material
(defun C:CHTXT ()
(setq ss (ssget "X"
(list '(0 . "TEXT,MTEXT")
'(-4 . "<AND")
'(-4 . "<OR")
(cons 1 "F-123")
(cons 1 "F-506")
'(-4 . "OR>")
'(-4 . "AND>")
)
)
)
(if (> (sslength ss) 1)
(progn
(setq i -1)
(while (and (setq e (ssname ss (setq i (1+ i))))
(setq ed (entget e))
(setq str (cdr (assoc 1 ed)))
(setq newstr (cond ((= str "F-123") "F0123")
((= str "F-506") "F0106")
)
)
)
(entmod (setq ed (subst (cons 1 newstr) (assoc 1 ed) ed)))
(entupd e)
);while
);progn
);if
(princ)
);defun
:::Happy Mtexting or Texting....
RE: How to find and replace text strings with no dialogs?
The routine I posted is good for 2 or more occurrences.
If there's only 1, it won't work.
RE: How to find and replace text strings with no dialogs?
in all drawings at once as batch process:
members.fortunecity.com/tigrek/
www.homescript.com/autocad/