明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 802|回复: 3

[提问] 递增复制如何修改成连续递增复制

[复制链接]
发表于 2020-7-1 16:34 | 显示全部楼层 |阅读模式
下面是从论坛淘来的递增复制功能,原作者已经忘了是谁了  想改成按空格重复前一次的距离和方向 ,右键退出,如何修改?还有如何修改成带阵列的递增?
  1. ;;;递增复制

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

 楼主| 发表于 2020-10-26 12:31 | 显示全部楼层
sharetow 发表于 2020-7-2 08:08
你试试这个。
http://bbs.mjtd.com/thread-180675-1-1.html

我想要源码 这个参数太多了 不符合我的个人习惯
回复 支持 1 反对 0

使用道具 举报

发表于 2020-7-2 08:08 | 显示全部楼层

点评

这个是精品  发表于 2020-7-2 09:27
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-9 06:59 , Processed in 0.331469 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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