本帖最后由 作者 于 2010-10-28 18:26:47 编辑
;;;文字递增
;;;根据caoyin的刷子函数写成如下函数;空格键不能中断
;;;;;;;;;;;; ;;;功能,如果是文字末尾不是数,则加1.如果是数,取出来作为基数HH:Textnum (defun textIncrease ( / BOOL E ENT HH:TEXTNUM HH:TEXTPRE I OB1 OBA OBALENGTH OBN OBT OTXT PTN) (lt:error-init (list nil 0 nil)) ;;;取得文字 (setq bool T) (while bool (setq ob1 (entsel "\n选择要修改的任何文本:")) (SETQ obn (car ob1) ;图元 ptn (car (cdr ob1)) ;拾取点 ) ;_ 结束SETQ (setq obt (car (nentselp ptn))) (setq oba (cdr (assoc 0 (entget obt)))) (if (or (= oba "TEXT") (= oba "MTEXT") (= oba "ATTRIB") (= oba "ATTDEF") ) ;_ 结束or (setq bool nil) (princ "\n必须选择文字,重来:") ) ;_ 结束if ) ;end while
(setq ent (entget obt)) (if (= oba "ATTDEF") (setq otxt (cdr (assoc 2 ent))) (setq otxt (cdr (assoc 1 ent))) ) ; end if
(if (obaEndIsNumber otxt) (progn (setq bool T i 0) (setq obaLength (strlen otxt)) (while bool (setq e (ascii (substr otxt obaLength 1))) (if (or (and (> e 47) (< e 58))) (progn (setq obaLength (1- obaLength)) (setq i (1+ i)) ) (setq bool nil) ) ;_ 结束if (if (= i (strlen otxt)) (setq bool nil)) ) ;_ 结束while (setq obaLength (- (strlen otxt) i));前缀长度 (setq HH:Textpre (substr otxt 1 obaLength)) (setq HH:Textnum (substr otxt (+ 1 obaLength) i)) ) ;_ 结束progn (progn (setq HH:Textpre otxt) (setq HH:Textnum "1") (setq otxt (strcat otxt "1")) (if (= oba "ATTDEF") (progn (entmod (subst (cons 2 otxt) (assoc 2 ent) ent)) (entupd obn) ) ;_ 结束progn (progn (entmod (subst (cons 1 otxt) (assoc 1 ent) ent)) (entupd obn) ) ;_ 结束progn ) ;_ 结束if ) ;_ 结束progn ) ;_ 结束if
(lt:match (cadr ob1) '(2 2) (list "\n选择要改变的文字: " '((0 . "*TEXT,INSERT")) ) ;_ 结束list '(lambda (x / ent) ;;;(setq x (car (entsel))) (setq ent (entget x)) (setq HH:Textnum (itoa (1+ (atoi HH:Textnum)))) (setq otxt (strcat HH:Textpre HH:Textnum)) ;;;获得块名,之后用entnext访问它的名成元 (if (= "INSERT" (cdr (assoc 0 ent))) (progn (setq firn (ENTNEXT (CDR (ASSOC -1 ENT)))) (if firn (setq bool T)) (while bool (SETQ ENT (ENTGET firn)) (if (or (= (CDR (ASSOC 0 ent)) "TEXT") (= (CDR (ASSOC 0 ent)) "MTEXT") (= (CDR (ASSOC 0 ent)) "ATTRIB") ) ;_ end of or (progn (entmod (subst (cons 1 otxt) (assoc 1 ent) ent)) (setq bool nil) ) ;_ end of progn (progn (if (= (cdr (assoc 0 ent)) "ATTDEF") (entmod (subst (cons 2 otxt) (assoc 2 ent) ent)) (setq bool nil) ) ;_ end of if ) ;_ end of progn ) ;_ end of if (entupd firn) (entupd x) (setq firn (entnext firn)) (if firn (setq bool nil) ) ;_ end of if ) ;_ end of while ) ;_ end of progn (entmod (subst (cons 1 otxt) (assoc 1 ent) ent)) ) ;_ end of if
) ;_ 结束lambda ) ;_ 结束lt:match (lt:error-restore)
) ;_ 结束defun
;;;所取字符串末尾是不是数,返回真假 (defun obaEndIsNumber (otxt / E OBALENGTH) (setq obaLength (strlen otxt)) (setq e (ascii (substr otxt obaLength 1))) (and (> e 47) (< e 58)) ) ;_ 结束defun ;;; 结束defun obaEndIsNumber
|