本帖最后由 muwind 于 2021-1-8 23:35 编辑
;允许部分替换,可能出现想不到的结果
;比如会把替换400成200会把2400换成2200
(defun c:tt ( / ss edat getdim N m str1 str2)
(setq str1 (getstring "\n 请输入需要替换的尺寸:")
str2 (getstring "\n 您想替换成什么?:")
m 0
)
(setq ss (ssget "x" (list (cons 0 "dim*"))));选择所有尺寸
(repeat (setq N (sslength SS))
(setq getdim (ssname ss (setq N (1- N))))
(setq edat ( getdimtext getdim))
(if (vl-string-search str1 edat )
(progn
(setq edat (vl-string-subst str2 str1 edat))
(entmod (subst (cons 1 edat) (assoc 1 (entget getdim)) (entget getdim) ))
(setq m (1+ m))
)
)
);repeat
(if (> m 0)
(princ (strcat "共" (rtos m 2 0) "个尺寸替换完成"))
(princ "我很努力了,但什么忙也没帮上")
)
(princ)
)
- ;全替换
- (defun c:tt ( / ss edat getdim N m str1 str2)
- (setq str1 (getstring "\n 请输入需要替换的尺寸数值:")
- str2 (getstring "\n 您想替换成什么?:")
- m 0
- )
- (setq ss (ssget "x" (list (cons 0 "dim*"))));选择所有尺寸
- (repeat (setq N (sslength SS))
- (setq getdim (ssname ss (setq N (1- N))))
- (setq edat ( getdimtext getdim))
- (if (= str1 edat )
- (progn
- (entmod (subst (cons 1 str2) (assoc 1 (entget getdim)) (entget getdim) ))
- (setq m (1+ m))
- )
- )
- );repeat
- (if (> m 0)
- (princ (strcat "共" (rtos m 2 0) "个尺寸替换完成"))
- (princ "我很努力了,但什么忙也没帮上")
- )
- (princ)
- )
|