以下程序,为上面所改。还需要完善的,
(1)属性块,块中的文字,还是无法改。
(2)多行文本,改了不能立马展现,需要再运行一次程序。
- (defun c:tt (/ ff data num txtcontent txtcontent2 txtlst ss i ssn endata)
- ;**********读取txt文件
- ;;;(setq data_file (getfiled "请选择字符替换的文本" "d:\\test1" "txt" 2))
- (SETQ data0 '(
- "Q235-A,Q235-B"
- "T1,TA"
- "T2,TB"
- "T3,TC"
- "T4,TD"
- "T5,TE"
- "T6,TF"
- )
- ii 0
- )
- ;;;(setq ff (open data_file "r"));打开文件
- ;;;(setq data (read-line ff)) ;读取一行
- (SETQ DATA (NTH ii data0))
- (while data
- (setq ii (1+ ii))
- (setq num (vl-string-position (ascii ",") data))
- ;***********拾取替换文本
- (setq txtcontent (substr data 1 num))
- (setq txtcontent2 (substr data (+ num 2)))
- (setq txtlst (list '(0 . "TEXT,MTEXT") (cons 1 txtcontent)))
- (setq ss (ssget "X" txtlst)) ;;全匹配
- ;;;(setq ss (ssget txtlst))
- (if ss (progn
- (setq i 0)
- (repeat (sslength ss)
- (setq ssn (ssname ss i))
- (setq endata (entget ssn))
- (setq endata (subst (cons 1 txtcontent2) (assoc 1 endata) endata))
- (entmod endata) ;;界面刷新
- (setq i (1+ i))
- )
- )
- ;***********完成替换
- (SETQ DATA (NTH ii data0))
- )
- )
- )
|