找回密码
 [加入论坛]
查看: 1268|回复: 1

一个件号加的程序,件14-0可以直接变成15-0

[复制链接]
xiaoxiao 发表于 2005-4-7 00:20 | 显示全部楼层 |阅读模式
<>是本论坛会员发布的,因为在贴后面,估计很少有人看到,但本程序个人觉得很有用</P>
<P>这是一个件号加的程序,件14-0可以直接变成15-0</P>
<P>(setq n_add 1 addflag 1)</P>
<P>(defun c:add(/ l i m o oldstr oldi newstr i1 i2 first sec third)
   (setq olderr  *error*    *error* chgterr     chm     0)
   (setq n_add0 n_add i 1 i1 nil i2 nil)
   (setq n_add (getint (strcat "\n输入整数值&lt;" (itoa n_add) "&gt;:")))
   (if (not n_add)  (setq n_add n_add0))
   
   (while (setq o (entsel))
      (setq oldstr  (cdr (assoc '1 (entget (car o)))))
      (setq oldi (atoi oldstr))
      (setq l (strlen oldstr))
      (repeat l
   (if (= "-" (substr oldstr i 1))       ;The following example:
       (if i1 (setq i2 i) (setq i1 i))   ;if 10-1-1 then i1=3;i2=5
   )                                     ;if 10-1   then i1=3;i2=nil
   (setq i (1+ i))                       ;if 10     then i1,i2=nil
      )
      (cond
   ((and (&lt;= l 3) (= i1 nil) (= i2 nil))            ;10, 210, 3462, ...
      (setq newstr (+ oldi n_add)))
   ((and (&gt;= l 3) (&lt;= l 4) (= "0" (substr oldstr l 1))) ;10-0
      (setq newstr (strcat (itoa (+ oldi n_add)) "-0"))
   )
   ((and (&gt;= l 3) (&lt;= l 5) (/= "0" (substr oldstr l 1)));10-1
      (setq first (substr oldstr 1 i1))
      (setq oldi (atoi (substr oldstr (1+ i1) 2)))
      (setq newstr (strcat first (itoa (+ oldi n_add))))
   )
   ((and (&gt;= l 5) (= "0" (substr oldstr l 1)))            ;10-1-0
      (setq first (substr oldstr 1 i1))
      (setq oldi (atoi (substr oldstr (1+ i1) (- i2 i1 1))))
      (setq newstr (strcat first (itoa (+ oldi n_add)) "-0"))
   )
   ((and (&gt;= l 5) (/= "0" (substr oldstr l 1)))           ;10-1-1
      (setq first (substr oldstr 1  ))
      (setq oldi (atoi (substr oldstr (1+ i2) (- l i2))))
      (setq newstr (strcat first (itoa (+ oldi n_add))))
   )
      );cond
      (if (= addflag -1)
          (command "change" o "" "" "" "" ""  newstr)
          (command "change" o "" "" "" "" "" "" newstr)
      )
      (setq i 1 i1 nil i2 nil)
   );while
)</P>
koalabear 发表于 2005-4-7 00:41 | 显示全部楼层
不错的程序阿。以前见过一个是尾数加的。
回复 顶 踩

使用道具 举报

您需要登录后才可以回帖 登录 | [加入论坛]

本版积分规则

手机版|化工技术网- 赠人玫瑰 手有余香 ( 苏ICP备14035884号 )

GMT+8, 2026-12-1 22:45

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表