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