Results 1 to 1 of 1

Thread: copy and increment text

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2018-07
    Posts
    1
    Login to Give a bone
    0

    Default copy and increment text

    hi guys! someone out there check my lsp code i was trying to figure out
    how can i change this format 0001-02-01 to 0001-02-02, 0001-02-03, 0001-02-04 and so on....

    Code:
    (defun c:I-2(/ *Error* Inc Ent Obj OldStr Mode
    NewStr OldNum Lst Res Pt)
    
    (defun *Error* (Msg)
    (cond
    ((or (not Msg)
    (member Msg '("console break"
    "Function cancelled"
    "quit / exit abort"))))
    ((princ (strcat "\nError: " Msg)))
    ) ;cond
    (setvar "cmdecho" 1)
    (princ)
    ) ;end
    
    (vl-load-com)
    
    (defun Str2Num (str / test numlst lst)
    (setq test (list 46 48 49 50 51 52 53 54 55 56 57))
    (setq charlst (vl-string->list str))
    (foreach x charlst
    (if (member x test)
    (setq lst (cons x lst))
    (setq lst (cons 32 lst))
    )
    )
    (read (vl-list->string (reverse lst)))
    )
    
    (defun DecimalTest (str)
    (if
    (or
    (= "." (substr str 1 1))
    (= "-." (substr str 1 2))
    (= "-.-" (substr str 1 3))
    )
    (vl-princ-to-string (atof str))
    str
    )
    )
    
    (defun PickTest ()
    (while
    (or
    (null (setq Obj (entsel "\nSelect text to increment or Cancel to end:
    ")))
    (and
    (/= "MTEXT" (cdr (assoc 0 (entget (car Obj)))))
    (/= "TEXT" (cdr (assoc 0 (entget (car Obj)))))
    ) ;and
    ) ;or
    (setq Obj (entsel "\nText object not selected - try again: "))
    ) ;while
    ) ;end
    
    (setvar "cmdecho" 0)
    (setq Inc (read (DecimalTest
    (getstring "\nEnter increment value positive or negative: "))))
    (initget 1 "Y N ")
    (setq Mode (getkword "\nCopy text [Yes/No] : "))
    (if (or (= Mode "") (= Mode "N"))
    (setq Mode "N")
    )
    
    (while T ;repeat
    (cond
    ((= Mode "N")
    (PickTest)
    (setq Ent (car Obj))
    ) ;cond
    ((= Mode "Y")
    (if (null Ent)
    (progn
    (PickTest)
    (setq Ent (car Obj) Pt (cadr Obj))
    (command ".copy" Ent "" Pt pause)
    (setq Ent (entlast))
    )
    (progn
    (command ".copy" (entlast) "" (getvar "lastpoint") pause)
    (setq Ent (entlast))
    )
    ) ;if
    ) ;cond
    ) ;cond
    
    (setq Lst (entget Ent))
    (setq OldStr (DecimalTest (cdr (assoc 1 (entget Ent)))))
    (setq OldNum (Str2Num OldStr))
    (if OldNum
    (progn
    (setq Res (+ Inc OldNum)
    Res (vl-princ-to-string Res)
    OldNum (vl-princ-to-string OldNum)
    NewStr (vl-string-subst Res OldNum OldStr 0)
    Lst (subst (cons 1 NewStr) (assoc 1 Lst ) Lst))
    
    (entmod Lst)
    (entupd Ent)
    )
    (princ "\nNumber not found in text object ")
    ) ;if
    ) ;while
    (*Error* nil)
    (princ)
    ) ;end
    
    ;shortcut
    (defun c:IT () (c:IncrementText))

    in this code i was able to change 0001-02-01 to 0002-02-01, 0003-02-01, 0004-02-01 and so on
    please i wiil be very greatful if some does thanks!!!
    Last edited by Wanderer; 2018-07-31 at 02:01 PM. Reason: please use code tags and do not post your question more than once, thanks!

Similar Threads

  1. Replies: 5
    Last Post: 2016-08-11, 11:35 PM
  2. Increment Selected Text
    By rjb709739 in forum AutoLISP
    Replies: 10
    Last Post: 2015-10-05, 01:03 PM
  3. 2013: Copy and Increment Text
    By nlrdavid in forum AutoCAD General
    Replies: 6
    Last Post: 2013-05-16, 06:46 PM
  4. Increment Text
    By robert.1.hall72202 in forum AutoLISP
    Replies: 11
    Last Post: 2007-01-11, 08:11 PM
  5. Increment Text Numbers
    By larry.80915 in forum AutoCAD General
    Replies: 2
    Last Post: 2005-01-12, 05:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •