 - ;;; 文本批量替换根据cabinsummer程序整理。
- (defun c:PLLISP (/ ct0 ct1 ct2 edata etext newch newtext oldch readch schct ssl sstxt subln txtln)
- (setvar "cmdecho" 0)
- (setq list1 (list "172.00-76.00" "172.00-77.00" "171.20-76.00" "171.20-77.00" "170.40-76.00" "170.40-77.00" "169.60-76.00" "169.60-77.00" "169.60-78.00" "168.80-76.00" "168.80-77.00" "168.80-78.00" "168.00-76.00" "168.00-77.00" "168.00-78.00" "167.20-75.00" "167.20-76.00" "167.20-77.00" "167.20-78.00" "166.40-77.00" "166.40-78.00" "166.40-79.00" "165.60-77.00" "164.80-77.00" "164.00-78.00"))
- (setq list2 (list "I02160077" "I02160078" "I02150077" "I02150078" "I02140077" "I02140078" "I02130077" "I02130078" "I02130079" "I02120077" "I02120078" "I02120079" "I02110077" "I02110078" "I02110079" "I02100076" "I02100077" "I02100078" "I02100079" "I02090078" "I02090079" "I02090080" "I02080078" "I02070078" "I02060079"))
- (setq n 0)
- (setq m (length list1)) ;返回表中的元素的个数
- (while (< n m)
- (setq oldch (nth n list1) ; 要查找的文本内容,自己修改
- newch (nth n list2) ; 要替换的文本内容,自己修改
- )
- (if (and
- (/= "" oldch)
- (/= oldch newch)
- (setq sstxt (ssget "x" '((0 . "*TEXT"))));选择所有数据
- )
- (progn
- (setq ssl (sslength sstxt) ;求出一个选择集中的对象(图元)数目,并将其作为一个整数返回
- ct0 0
- ct1 0
- ct2 0
- subln (strlen oldch)
- )
- (while (< ct0 ssl)
- (setq edata (entget (ssname sstxt ct0))
- etext (cdr (assoc 1 edata))
- txtln (strlen etext)
- schct 1
- newtext ""
- )
- (while (<= schct txtln)
- (setq newtext (strcat newtext (if (= (setq readch (substr etext schct subln))
- oldch
- )
- (setq ct1 (1+ ct1)
- schct (+ schct subln)
- newch newch
- )
- (progn
- (setq schct (1+ schct))
- (substr readch 1 1)
- )
- )
- )
- )
- )
- (if (/= etext newtext)
- (progn
- (entmod (subst
- (cons 1 newtext)
- (assoc 1 edata)
- edata
- )
- )
- (setq ct2 (1+ ct2))
- )
- )
- (setq ct0 (1+ ct0))
- )
- )
- )
- (setq n (1+n))
- )
- (princ)
- )
我想查找表list1中的元素,如果找到将其替换成list2中对应的元素。
但是程序执行了没反应,没有想要的效果,求解~~
|