求各位大师帮修改一下 ,修改文本,现在有一个程序,只能修改一个文字,现在要求能替换 2种文字
1,模具费 几个字 改成 修改模具费用 这个功能已经有了
2,零件费用 改成 模具配件 ,把零件费用4个字 改成模具配件4个字 增加这一个功能
现在用的程序如下:
(defun chgterr (s / p)
(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:CHGTEXT (/ p l n e os as ns st s nsl osl sl si chf chm olderr)
(setq olderr *error* ; Initialize variables
*error* chgterr
chm 0)
(setq p (ssget "all")) ; Select objects
(if p (progn ; If any objects selected
; (while (= 0 (setq osl (strlen (setq os (getstring t "\nOld string: ")))))
(while (= 0 (setq osl (strlen (setq os "模具费"))))
(princ "Null input invalid")
)
; (setq nsl (strlen (setq ns (getstring t "\nNew string: "))))
(setq nsl (strlen (setq ns "修改模具费用")))
(setq l 0 n (sslength p))
(while (< l n) ; For each selected object...
(setq e (entget (ssname p l)))
(cond ((= "TEXT" (cdr (assoc 0 e))) ; Look for TEXT entity type (group 0)
(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))
))
) ; Treat TEXT entity type (group 0)
((= "MTEXT" (cdr (assoc 0 e))) ; Look for MTEXT entity type (group 0)
(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 MTEXT entity
(setq chm (1+ chm))
))
) ; Treat MTEXT entity type (group 0)
((= "ATTDEF" (cdr (assoc 0 e))) ; Look for Attrib entity type (group 0)
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 2 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 2 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
) ; Treat TEXT entity type (group 0)
) ;cond
(setq l (1+ l))
)
))
(princ "Changed ") ; Print total lines changed
(princ chm)
(princ " text lines.")
(terpri)
(setq *error* olderr) ; Restore old *error* handler
(princ)
)
(defun c:jiamu2cege()
(C:CHGTEXT)(princ)
)
(princ)