zhengchuan 发表于 2012-5-28 09:21
虽然觉得查找替换也很方便,但就是想能再快的。。时间就是金钱啊
帮你改了一个,不知道合不合胃口。- (defun C:CHTEXT (/ p l n e os as ns st s nsl osl sl si chf chm cont)
- (setq chm 0 p (ssget)) ; Select objects
- (if p
- (progn ; If any objects selected
- (setq cont t)
- (while cont
- (setq osl (strlen (setq os "(")))
- (if (= osl 0)
- (princ "Null input invalid")
- (setq cont nil)
- )
- )
- (setq nsl (strlen (setq ns "(")))
- (setq l 0 n (sslength p))
- (while (< l n)
- (if (OR (= "MTEXT"
- (cdr (assoc 0 (setq e (entget (ssname p l))))))
- (= "TEXT"
- (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))
- )
- (setq cont t)
- (while cont
- (setq osl (strlen (setq os ")")))
- (if (= osl 0)
- (princ "Null input invalid")
- (setq cont nil)
- )
- )
- (setq nsl (strlen (setq ns ")")))
- (setq l 0 n (sslength p))
- (while (< l n)
- (if (OR (= "MTEXT"
- (cdr (assoc 0 (setq e (entget (ssname p l))))))
- (= "TEXT"
- (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 "共修改了 ") ; Print total lines changed
- (princ chm)
- (princ " 个西文括号.")
- (terpri)
- )
|