
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to find/replace all step numbers in a drawing file, based on an excel sheet with new/old step numbers. My automation starts with excel vba to get two arrays of Old Step and New Step numbers to submit into the find replace. The excel vba then sends commands to autocad to run a lisp I wrote to cycle through and find replace each of the items in the array. For some reason, it will change the first instance (encircled) but not the second instance (part of a description). Is there something in my LISP that is keeping it from replacing all instances?
; CHGTEXT.LSP
; CHANGES TEXT GLOBALLY
; This program will replace every occurrence of an "old string" with a
; "new string".
(defun chgterr (s)
(if (/= s "Function cancelled")
(princ (strcat "\nError: " s))
)
(setq p nil)
(setq *error* olderr)
(princ)
)
(defun C:CHGTEXT (/ p l n e os as ns st s nsl osl sl si chf chm olderr)
(setq olderr *error*
*error* chgterr
chm 0)
(setq p (ssget "x" '((0 . "MTEXT"))))
(ssget "x" '((0 . "MTEXT")))
(if p (progn
(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)
(if (= "MTEXT"
(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)
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn
(setq e (subst (cons 1 s) as e))
(entmod e)
(setq chm (1+ chm))
))
)
)
(setq l (1+ l))
)
))
(princ "Changed ")
(princ chm)
(princ " text lines.")
(terpri)
(setq *error* olderr)
(princ)
)
Solved! Go to Solution.