明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 16239|回复: 44

文字末尾的数字递增复制-优化版

    [复制链接]
发表于 2013-4-4 18:05 | 显示全部楼层 |阅读模式
本帖最后由 NetBee 于 2013-4-7 17:18 编辑

原帖见wowan1314的
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=92879

优化了一下,但还是仅支持尾数。
见有些网友发布的支持中间数字递增,有些的能字母递增。
精力有限,也希望大家共同来优化完善。





  1. ;;; 拷贝数字 数字自动增加程序
  2. ;;;原代码参 wowan1314
  3. ;;;1.1 修改 by netbee 2013.04.05
  4. ;;;1.2 修改 by netbee 2013.04.05
  5. ;;;可以包含其他对象,如圆中数字。
  6. ;;;1.3 修改 by netbee 2013.04.06
  7. ;;;修复DIMZIN变量影响。

  8. ;;;可再次优化为中间数字递增,字母递增等
  9. ;;
  10. (defun c:NBTC_TXTCopyadd (/             fun_setini        fun_close  fun_error  FUN_GETdigit            old_error old_DIMZIN ureal          last_ent
  11.                           Plus1             String_To_Numbers           buchang1   $buchang         SS            SS1               e0          ent
  12.                           PT             i                loop           ENTL              E-1         NEWTX            ENT_TMP
  13.                          )
  14.   (defun fun_setini ()
  15.     (setq old_error *error*
  16.           old_DIMZIN(getvar "DIMZIN")
  17.           *error* fun_error
  18.     )
  19.     (or NBTV_TXT_CopyADD (setq NBTV_TXT_CopyADD 1.0))
  20.     (setvar "cmdecho" 0)
  21.     (setvar "DIMZIN" 0)
  22.     (vl-cmdf "_.undo" "be")
  23.   )
  24.   (defun fun_error (msg) (princ msg) (fun_close))
  25.   (defun fun_close () (vl-cmdf "_.undo" "e") (setvar "DIMZIN" old_DIMZIN)(setvar "cmdecho" 1) (setq *error* old_error))
  26.   (defun ureal (bit kwd msg def / inp)
  27.     (if        def
  28.       (setq msg        (strcat "\n" msg "<" (rtos def 2) ">: ")
  29.             bit        (* 2 (fix (/ bit 2)))
  30.       )
  31.       (setq msg (strcat "\n" msg ": "))
  32.     )
  33.     (initget bit kwd)
  34.     (setq inp (getreal msg))
  35.     (if        inp
  36.       inp
  37.       def
  38.     )
  39.   )
  40.   (defun String_To_Numbers (inStr
  41.                             ;;Input string
  42.                             / Flush_Buf        Res
  43.                             ;;Result list
  44.                             Buf
  45.                             ;;String buffer
  46.                             Inx
  47.                             ;;Character location
  48.                             CH
  49.                             ;;Character
  50. )   (defun Flush_Buf ()
  51.       (if (not (wcmatch Buf "[+-.]"))        ;is it not just +-.
  52.         (progn                                ;Clean it up first
  53.           (if (= (substr Buf 1 1) ".")
  54.             (setq Buf (strcat "0" Buf))
  55.           )
  56.           ;;add zero to front if .#
  57.           (if (= (substr Buf (strlen Buf)) ".")
  58.             (setq Buf (substr Buf 1 (1- (strlen Buf))))
  59.           )
  60.           ;;remove decimal if #.
  61.                                         ;Add to RES list
  62.           (setq RES (cons Buf RES))
  63.         )
  64.       )
  65.       (setq Buf "")
  66.       ;;reset Buf
  67.     )
  68.     (setq Inx 1                                ;start at the beginning of the string
  69.           Buf ""                        ;init buffer to empty
  70.     )                                        ;
  71.                                         ; Loop until the end of the string.
  72.                                         ; (I indicates where we are in the string)
  73.                                         ;
  74.     (while (<= Inx (strlen inStr))        ;
  75.                                         ; Get the character at position Inx, increment position indicator
  76.       (setq CH        (substr inStr Inx 1)
  77.             Inx        (1+ Inx)
  78.       )                                        ;
  79.       (cond                                ; Test to see if character is a digit.
  80.         ((wcmatch CH "[0-9.]")
  81.          (if (= CH ".")                        ;is it decimal
  82.            (if (not (wcmatch Buf "*`.*")) ;not already in there
  83.              (setq Buf (strcat Buf CH))
  84.              (Flush_Buf)
  85.            )                                ;
  86.            (setq Buf (strcat Buf CH))
  87.          )
  88.         )
  89.         ((= Buf "")                        ;is the buffer empty
  90.                                         ;Is CH minus
  91.          (if (= CH "-")
  92.            (setq Buf CH)                ;Yes, save in Buf
  93.          )
  94.         )
  95.         ('T                                ;else buffer is not empty
  96.          (Flush_Buf)
  97.          (if (= CH "-")
  98.            (setq Buf CH)
  99.          )
  100.         )
  101.       )                                        ; End of COND
  102.     )                                        ; End of WHILE
  103.                                         ;
  104.     (if        (and (/= Buf "") (not (wcmatch Buf "[+-.]")))
  105.       (Flush_Buf)
  106.     )
  107.     (reverse Res)
  108.   )
  109.   (defun FUN_GETdigit (sNum)
  110.     (IF        (vl-string-search "." sNum)
  111.       (STRLEN (substr sNum (+ 2 (vl-string-search "." sNum))))
  112.       0
  113.     )
  114.   )
  115.   (defun Plus1 (str buchang / d1 d2 h num1 num2)
  116.     (setq str (vl-string-translate "-" (chr 1) str))
  117.     (or (setq d1 (last (string_to_numbers str))) (setq d1 "0"))
  118.     (setq h (vl-string-right-trim d1 str))
  119.     (setq num1 (FUN_GETdigit d1))
  120.     (setq d2 (vl-string-right-trim "." (vl-string-right-trim "0" (RTOS (+ (read d1) buchang) 2 12))))
  121.     (setq num2 (FUN_GETdigit d2))
  122.     (if        (and (= num2 0) (> num1 0))
  123.       (setq d2 (strcat d2 "."))
  124.     )
  125.     (repeat (- num1 num2) (setq d2 (strcat d2 "0")))
  126.     ;;(setq d2 (vl-princ-to-string (+ (read d1) buchang)))
  127.     (while (< (strlen d2) (strlen d1)) (setq d2 (strcat "0" d2)))
  128.     (vl-string-translate (chr 1) "-" (strcat h d2))
  129.   )
  130.   (defun last_ent (en / ss)
  131.     (if        en
  132.       (progn (setq ss (ssadd))
  133.              (while (setq en (entnext en))
  134.                (if (not (member (cdr (assoc 0 (entget en))) '("ATTRIB" "VERTEX" "SEQEND")))
  135.                  (ssadd en ss)
  136.                )                        ;if
  137.              )                                ;while
  138.              (if (zerop (sslength ss))
  139.                (setq ss nil)
  140.              )
  141.              ss
  142.       )                                        ;progn
  143.       (ssget "_x")
  144.     )                                        ;if
  145.   )
  146.   ;;-------------
  147.   (fun_setini)
  148.   (if (setq $buchang (ureal 1 "" "\n增减值(正为增,负为减)" NBTV_TXT_CopyADD))
  149.     (setq NBTV_TXT_CopyADD $buchang)
  150.   )
  151.   (setq ss (ssget ))
  152.   (setq e0 (entlast))
  153.   (setq pt (getpoint "指定基点:"))
  154.   (command "copy" ss "" pt pause)
  155.   (setq loop T)
  156.   (if (= 0 (distance (setq Point (getvar "LastPoint")) pt)) ;判断最后一点是不是pt点.
  157.     (progn (setq loop nil)                ;Right Button
  158.            (setq ent_tmp (LAST_ENT e0))        ;ent_tmp 是e0后生成的物体.
  159.            (command "_.erase" ent_tmp "")
  160.     )
  161.     (setq pt Point)
  162.   )
  163.   (while loop
  164.     (SETQ SS1 (last_ent E0)
  165.           I   0
  166.     )
  167.     (repeat (sslength ss1)
  168.       (setq ent         (ssname ss1 i)
  169.             i         (1+ i)
  170.             entl (entget ent)
  171.       )                                        ;图元资料
  172.       (if (wcmatch (cdr (assoc 0 entl)) "*TEXT")
  173.         (progn (setq e-1   (cdr (assoc 1 entl))
  174.                      ;;文字内容
  175.                      NEWTX (Plus1 E-1 NBTV_TXT_CopyADD)
  176.                )
  177.                (entmod (subst (cons 1 NEWTX) (assoc 1 entl) entl)) ;更新文字
  178.         )
  179.       )
  180.     )                                        ;end repeat  
  181.     (setq e0 (entlast))
  182.     (command "copy" ss1 "" pt pause)
  183.     (setq Point (getvar "LastPoint"))
  184.     (if        (= 0 (distance Point pt))        ;判断最后一点是不是pt点.
  185.       (progn (setq loop nil)                ;Right Button
  186.              (setq ent_tmp (LAST_ENT e0)) ;ent_tmp 是e0后生成的物体.
  187.              (command "_.erase" ent_tmp "")
  188.       )
  189.       (progn (setq pt Point)
  190.              ;;(setq ss (LAST_ENT e0))
  191.       )
  192.     )
  193.   )
  194.   (fun_close)
  195.   (princ)
  196. )

  197. (princ "复制文字增加数字 NBTC_TXTCopyadd")





该贴已经同步到 NetBee的微博

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

评分

参与人数 1明经币 +1 收起 理由
ucuc2003 + 1 精益求精!赞!

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下

本帖被以下淘专辑推荐:

发表于 2022-10-5 18:44 | 显示全部楼层
本帖最后由 没有昵称呀 于 2022-10-5 18:49 编辑
NetBee 发表于 2013-4-7 17:20
已经修复,原来是dimzin搞的鬼。说明:不支持负数的,“-”是看成字符横杠的。

我也遇到这样的问题了
发表于 2022-3-25 11:32 | 显示全部楼层
很好的插件,已下载,试了论坛了很多数字递增的这个是最靠谱的
发表于 2022-10-5 20:28 | 显示全部楼层
如果能支持阵列递增就好了
发表于 2013-4-4 19:28 | 显示全部楼层
本帖最后由 kwok 于 2013-4-4 19:28 编辑

支持楼主,连字母也优化上吧,一般很少有增中间的吧.
 楼主| 发表于 2013-4-5 23:34 | 显示全部楼层
这次应该能用很长时间了吧。
发表于 2013-4-6 00:14 | 显示全部楼层
呵呵!论坛有个程序…好像叫点哪个加哪个吧!如果不确定要递增的是什么位置!可用那个程序!具体没测试!应该是不错的!有兴趣的可以找找看看
发表于 2013-4-6 16:42 | 显示全部楼层
递增末尾数字会出错,如p29,p30这里p30会变为p03,诸如此类,望楼主修改下
发表于 2013-4-6 23:12 来自手机 | 显示全部楼层
试了,也是上楼说的情况
 楼主| 发表于 2013-4-6 23:37 | 显示全部楼层
什么情况,怎么我的没有
cad是哪个版本?
发表于 2013-4-7 08:53 | 显示全部楼层
试下了,1-1.递增到10的话就又变回1-1了。负数的话,-0.-1.--0.--1.---0.---1就这情况
 楼主| 发表于 2013-4-7 17:20 | 显示全部楼层
本帖最后由 NetBee 于 2013-4-7 17:34 编辑

已经修复,原来是dimzin搞的鬼。说明:不支持负数的,“-”是看成字符横杠的。
发表于 2013-4-14 15:51 | 显示全部楼层
楼主程序如有中文字符就会出现“警告: 忽略展开 未知异常”,

请问能否改为支持中文字符,如“房间L1”“房间L2”等?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-3-29 08:30 , Processed in 0.248851 second(s), 38 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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