江南十笑 发表于 2020-7-1 16:34:48

递增复制如何修改成连续递增复制

下面是从论坛淘来的递增复制功能,原作者已经忘了是谁了想改成按空格重复前一次的距离和方向 ,右键退出,如何修改?还有如何修改成带阵列的递增?
;;;递增复制

(defun c:LWW223 (/             fun_setini      fun_closefun_errorFUN_GETdigit            old_error old_DIMZIN ureal          last_ent
    Plus1             String_To_Numbers         buchang1   $buchang         SS            SS1               e0          ent
    PT             i                loop         ENTL            E-1         NEWTX            ENT_TMP
)
(defun fun_setini ()
    (setq old_error *error*
      old_DIMZIN(getvar "DIMZIN")
      *error* fun_error
    )
    (or NBTV_TXT_CopyADD (setq NBTV_TXT_CopyADD 1.0))
    (setvar "cmdecho" 0)
    (setvar "DIMZIN" 0)
    (vl-cmdf "_.undo" "be")
)
(defun fun_error (msg) (princ msg) (fun_close))
(defun fun_close () (vl-cmdf "_.undo" "e") (setvar "DIMZIN" old_DIMZIN)(setvar "cmdecho" 1) (setq *error* old_error))
(defun ureal (bit kwd msg def / inp)
    (if      def
      (setq msg      (strcat "\n" msg "<" (rtos def 2) ">: ")
      bit      (* 2 (fix (/ bit 2)))
      )
      (setq msg (strcat "\n" msg ": "))
    )
    (initget bit kwd)
    (setq inp (getreal msg))
    (if      inp
      inp
      def
    )
)
(defun String_To_Numbers (inStr
      ;;Input string
      / Flush_Buf      Res
      ;;Result list
      Buf
      ;;String buffer
      Inx
      ;;Character location
      CH
      ;;Character
      )   (defun Flush_Buf ()
      (if (not (wcmatch Buf "[+-.]"))      ;is it not just +-.
      (progn                              ;Clean it up first
          (if (= (substr Buf 1 1) ".")
            (setq Buf (strcat "0" Buf))
          )
          ;;add zero to front if .#
          (if (= (substr Buf (strlen Buf)) ".")
            (setq Buf (substr Buf 1 (1- (strlen Buf))))
          )
          ;;remove decimal if #.
          ;Add to RES list
          (setq RES (cons Buf RES))
      )
      )
      (setq Buf "")
      ;;reset Buf
    )
    (setq Inx 1                              ;start at the beginning of the string
      Buf ""                        ;init buffer to empty
    )                                        ;
    ; Loop until the end of the string.
    ; (I indicates where we are in the string)
    ;
    (while (<= Inx (strlen inStr))      ;
      ; Get the character at position Inx, increment position indicator
      (setq CH      (substr inStr Inx 1)
      Inx      (1+ Inx)
      )                                        ;
      (cond                              ; Test to see if character is a digit.
      ((wcmatch CH "")
          (if (= CH ".")                        ;is it decimal
            (if (not (wcmatch Buf "*`.*")) ;not already in there
            (setq Buf (strcat Buf CH))
            (Flush_Buf)
            )                              ;
            (setq Buf (strcat Buf CH))
          )
      )
      ((= Buf "")                        ;is the buffer empty
          ;Is CH minus
          (if (= CH "-")
            (setq Buf CH)                ;Yes, save in Buf
          )
      )
      ('T                              ;else buffer is not empty
          (Flush_Buf)
          (if (= CH "-")
            (setq Buf CH)
          )
      )
      )                                        ; End of COND
    )                                        ; End of WHILE
    ;
    (if      (and (/= Buf "") (not (wcmatch Buf "[+-.]")))
      (Flush_Buf)
    )
    (reverse Res)
)
(defun FUN_GETdigit (sNum)
    (IF      (vl-string-search "." sNum)
      (STRLEN (substr sNum (+ 2 (vl-string-search "." sNum))))
      0
    )
)
(defun Plus1 (str buchang / d1 d2 h num1 num2)
    (setq str (vl-string-translate "-" (chr 1) str))
    (or (setq d1 (last (string_to_numbers str))) (setq d1 "0"))
    (setq h (vl-string-right-trim d1 str))
    (setq num1 (FUN_GETdigit d1))
    (setq d2 (vl-string-right-trim "." (vl-string-right-trim "0" (RTOS (+ (read d1) buchang) 2 12))))
    (setq num2 (FUN_GETdigit d2))
    (if      (and (= num2 0) (> num1 0))
      (setq d2 (strcat d2 "."))
    )
    (repeat (- num1 num2) (setq d2 (strcat d2 "0")))
    ;;(setq d2 (vl-princ-to-string (+ (read d1) buchang)))
    (while (< (strlen d2) (strlen d1)) (setq d2 (strcat "0" d2)))
    (vl-string-translate (chr 1) "-" (strcat h d2))
)
(defun last_ent (en / ss)
    (if      en
      (progn (setq ss (ssadd))
      (while (setq en (entnext en))
          (if (not (member (cdr (assoc 0 (entget en))) '("ATTRIB" "VERTEX" "SEQEND")))
            (ssadd en ss)
          )                        ;if
      )                              ;while
      (if (zerop (sslength ss))
          (setq ss nil)
      )
      ss
      )                                        ;progn
      (ssget "_x")
    )                                        ;if
)
;;-------------
(fun_setini)


(princ "\n选择要复制的文字")
(setq ss (ssget '((0 . "*TEXT"))))

;(setq ss (ssget ))
(setq e0 (entlast))

(initget "S")
(setq pt (getpoint "指定基点[设置步长(S)]:"))

( if                                                               ;如果需要设置参数
    (= pt "S")
    (progn
      (if (setq $buchang (ureal 1 "" "\n增減数(正为增,负为减)" NBTV_TXT_CopyADD))
       (progn
      (setq NBTV_TXT_CopyADD $buchang)
   (setq pt (getpoint "指定基点:"))
    )
      )
    )
   
)



(command "copy" ss "" pt pause)
(setq loop T)
(if (= 0 (distance (setq Point (getvar "LastPoint")) pt)) ;判斷最後壹點是不是pt點.
    (progn (setq loop nil)                ;Right Button
      (setq ent_tmp (LAST_ENT e0))      ;ent_tmp 是e0後生成的物體.
      (command "_.erase" ent_tmp "")
    )
    (setq pt Point)
)
(while loop
    (SETQ SS1 (last_ent E0)
      I   0
    )
    (repeat (sslength ss1)
      (setq ent         (ssname ss1 i)
      i         (1+ i)
      entl (entget ent)
      )                                        ;圖元資料
      (if (wcmatch (cdr (assoc 0 entl)) "*TEXT")
      (progn (setq e-1   (cdr (assoc 1 entl))
            ;;文字
            NEWTX (Plus1 E-1 NBTV_TXT_CopyADD)
          )
          (entmod (subst (cons 1 NEWTX) (assoc 1 entl) entl)) ;更新文字
      )
      )
    )                                        ;end repeat
    (setq e0 (entlast))
    (command "copy" ss1 "" pt pause)
    (setq Point (getvar "LastPoint"))
    (if      (= 0 (distance Point pt))      ;判斷最後壹點是不是pt點.
      (progn (setq loop nil)                ;Right Button
      (setq ent_tmp (LAST_ENT e0)) ;ent_tmp 是e0後生成的物體.
      (command "_.erase" ent_tmp "")
      )
      (progn (setq pt Point)
      ;;(setq ss (LAST_ENT e0))
      )
    )
)
(fun_close)
(princ)
)

江南十笑 发表于 2020-10-26 12:31:12

sharetow 发表于 2020-7-2 08:08
你试试这个。
http://bbs.mjtd.com/thread-180675-1-1.html

我想要源码 这个参数太多了 不符合我的个人习惯

sharetow 发表于 2020-7-2 08:08:48

你试试这个。
http://bbs.mjtd.com/thread-180675-1-1.html
页: [1]
查看完整版本: 递增复制如何修改成连续递增复制