明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2535|回复: 9

[源码] 数字递增,求改进

[复制链接]
发表于 2014-6-17 11:28 | 显示全部楼层 |阅读模式
  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:zf (/       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. 匹配任意单个非字母数值字符

  58.     (if (= (substr Buf (strlen Buf)) ".")
  59.       (setq Buf (substr Buf 1 (1- (strlen Buf))))
  60.     )
  61.     ;;remove decimal if #.
  62.           ;Add to RES list
  63.     (setq RES (cons Buf RES))
  64.   )
  65.       )
  66.       (setq Buf "")
  67.       ;;reset Buf
  68.     )
  69.     (setq Inx 1        ;start at the beginning of the string
  70.     Buf ""      ;init buffer to empty
  71.     )          ;
  72.           ; Loop until the end of the string.
  73.           ; (I indicates where we are in the string)
  74.           ;
  75.     (while (<= Inx (strlen inStr))  ;
  76.           ; Get the character at position Inx, increment position indicator
  77.       (setq CH  (substr inStr Inx 1)
  78.       Inx  (1+ Inx)
  79.       )          ;
  80.       (cond        ; Test to see if character is a digit.
  81.   ((wcmatch CH "[0-9.]")
  82.    (if (= CH ".")      ;is it decimal
  83.      (if (not (wcmatch Buf "*`.*")) ;not already in there
  84.        (setq Buf (strcat Buf CH))
  85.        (Flush_Buf)
  86.      )        ;
  87.      (setq Buf (strcat Buf CH))
  88.    )
  89.   )
  90.   ((= Buf "")      ;is the buffer empty
  91.           ;Is CH minus
  92.    (if (= CH "-")
  93.      (setq Buf CH)    ;Yes, save in Buf
  94.    )
  95.   )
  96.   ('T        ;else buffer is not empty
  97.    (Flush_Buf)
  98.    (if (= CH "-")
  99.      (setq Buf CH)
  100.    )
  101.   )
  102.       )          ; End of COND
  103.     )          ; End of WHILE
  104.           ;
  105.     (if  (and (/= Buf "") (not (wcmatch Buf "[+-.]")))
  106.       (Flush_Buf)
  107.     )
  108.     (reverse Res)
  109.   )
  110.   (defun FUN_GETdigit (sNum)
  111.     (IF  (vl-string-search "." sNum)
  112.       (STRLEN (substr sNum (+ 2 (vl-string-search "." sNum))))
  113.       0
  114.     )
  115.   )
  116.   (defun Plus1 (str buchang / d1 d2 h num1 num2)
  117.     (setq str (vl-string-translate "-" (chr 1) str))
  118.     (or (setq d1 (last (string_to_numbers str))) (setq d1 "0"))
  119.     (setq h (vl-string-right-trim d1 str))
  120.     (setq num1 (FUN_GETdigit d1))
  121.     (setq d2 (vl-string-right-trim "." (vl-string-right-trim "0" (RTOS (+ (read d1) buchang) 2 12))))
  122.     (setq num2 (FUN_GETdigit d2))
  123.     (if  (and (= num2 0) (> num1 0))
  124.       (setq d2 (strcat d2 "."))
  125.     )
  126.     (repeat (- num1 num2) (setq d2 (strcat d2 "0")))
  127.     ;;(setq d2 (vl-princ-to-string (+ (read d1) buchang)))
  128.     (while (< (strlen d2) (strlen d1)) (setq d2 (strcat "0" d2)))
  129.     (vl-string-translate (chr 1) "-" (strcat h d2))
  130.   )
  131.   (defun last_ent (en / ss)
  132.     (if  en
  133.       (progn (setq ss (ssadd))
  134.        (while (setq en (entnext en))
  135.          (if (not (member (cdr (assoc 0 (entget en))) '("ATTRIB" "VERTEX" "SEQEND")))
  136.      (ssadd en ss)
  137.          )      ;if
  138.        )        ;while
  139.        (if (zerop (sslength ss))
  140.          (setq ss nil)
  141.        )
  142.        ss
  143.       )          ;progn
  144.       (ssget "_x")
  145.     )          ;if
  146.   )
  147.   ;;-------------
  148.   (fun_setini)
  149.   (if (setq $buchang (ureal 1 "" "\n增减值(正为增,负为减)" NBTV_TXT_CopyADD))
  150.     (setq NBTV_TXT_CopyADD $buchang)
  151.   )
  152.   (setq ss (ssget ))
  153.   (setq e0 (entlast))
  154.   (setq pt (getpoint "指定基点:"))
  155.   (command "copy" ss "" pt pause)
  156.   (setq loop T)
  157.   (if (= 0 (distance (setq Point (getvar "LastPoint")) pt)) ;判断最后一点是不是pt点.
  158.     (progn (setq loop nil)    ;Right Button
  159.      (setq ent_tmp (LAST_ENT e0))  ;ent_tmp 是e0后生成的物体.
  160.      (command "_.erase" ent_tmp "")
  161.     )
  162.     (setq pt Point)
  163.   )
  164.   (while loop
  165.     (SETQ SS1 (last_ent E0)
  166.     I   0
  167.     )
  168.     (repeat (sslength ss1)
  169.       (setq ent   (ssname ss1 i)
  170.       i   (1+ i)
  171.       entl (entget ent)
  172.       )          ;图元资料
  173.       (if (wcmatch (cdr (assoc 0 entl)) "*TEXT")
  174.   (progn (setq e-1   (cdr (assoc 1 entl))
  175.          ;;文字内容
  176.          NEWTX (Plus1 E-1 NBTV_TXT_CopyADD)
  177.          )
  178.          (entmod (subst (cons 1 NEWTX) (assoc 1 entl) entl)) ;更新文字
  179.   )
  180.       )
  181.     )          ;end repeat  
  182.     (setq e0 (entlast))
  183.     (command "copy" ss1 "" pt pause)
  184.     (setq Point (getvar "LastPoint"))
  185.     (if  (= 0 (distance Point pt))  ;判断最后一点是不是pt点.
  186.       (progn (setq loop nil)    ;Right Button
  187.        (setq ent_tmp (LAST_ENT e0)) ;ent_tmp 是e0后生成的物体.
  188.        (command "_.erase" ent_tmp "")
  189.       )
  190.       (progn (setq pt Point)
  191.        ;;(setq ss (LAST_ENT e0))
  192.       )
  193.     )
  194.   )
  195.   (fun_close)
  196.   (princ)
  197. )

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



该贴已经同步到 俊林霖的微博
 楼主| 发表于 2014-6-17 11:29 | 显示全部楼层
希望论坛内的高手帮个忙  再进行优化哈  对数值进行加减   如7.50(800.00) 1.先对括号前的数字进行加减 (若我输入0.5)后,提示第二步 2.对括号内的数字进行加减(若我输入-0.5)后,提示第三部  3.选择基点 进行复制   在下感激不尽
发表于 2014-6-17 12:52 | 显示全部楼层
俊林霖 发表于 2014-6-17 11:29
希望论坛内的高手帮个忙  再进行优化哈  对数值进行加减   如7.50(800.00) 1.先对括号前的数字进行加减 ( ...



本帖子中包含更多资源

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

x
 楼主| 发表于 2014-6-17 14:01 | 显示全部楼层
xyp1964 发表于 2014-6-17 12:52

高手  很是感激  !! 但是我加载后出现:no function definition: XYP-CMDLA0  怎么回事?
发表于 2014-6-17 14:40 | 显示全部楼层
加载上xcad.vlx

本帖子中包含更多资源

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

x

点评

这个无效  发表于 2014-6-17 15:07
发表于 2014-6-29 11:26 | 显示全部楼层
思路大概是:
1.选取文本,分别分割出实数部分及文本部分( NUM1 STR1 NUM2 STR2 NUM3 STR3 NUM4 STR4......),论坛有相关的函数代码,搜搜即可。
2.设置递增参数n1 n2 n3 n4......,点选位置(getpoint).
3.实数部分按参数递增(setq  NUM1 (+NUM1 n1 ) ......),然后(strcat NUM1 STR1 NUM2 STR2 NUM3 STR3 NUM4 STR4......)连接起来
4.在点选位置(enmake )插入文字.
发表于 2014-9-30 20:26 | 显示全部楼层
能不能修改下,成为第02#箱,第03#箱,第04#箱------

本帖子中包含更多资源

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

x
发表于 2014-11-26 01:04 | 显示全部楼层
收藏,学习
发表于 2015-1-21 13:16 | 显示全部楼层
怎样增加回退处理?
发表于 2015-1-28 15:25 | 显示全部楼层
学习了,谢谢楼主分享,辛苦了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-20 21:29 , Processed in 0.197681 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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