Increase a number (01)->(02)

Discussion in 'AutoCAD' started by masterbike360, Jan 11, 2005.

  1. Hi all...
    Here went some one ask for a copy (print) of a drawing, we freeze this one in time. We copy the drawing to the folder "_Previous_Version" and we add a version number "Drawing-01.dwg" first time distribute...So when some one call, We always ask wich version he as. The drawing name is also included in our title block (Reactor).

    I try to devlop a lisp to copy/rename my drawing.
    My problem is to increase my version value. I'm able to catch the drawing in my folder.
    (setq Xdwgs (dos_dir (strcat FixDwgPrfx "*-*.dwg")))
    This return me a list. Than I remove the ".dwg" extension.
    (setq NewList (mapcar 'vl-filename-base Xdwgs))
    Now a would like the run thru the list to find the last version. If "Drawing-01" Increase this version by 1. So my new drawing version will be named "Drawing-02".

    Is this possible? Are I'm looking to far and a should let the user enter the new version???

    Any advise will be very appreciate...
    Thanks, Simon
     
    masterbike360, Jan 11, 2005
    #1
  2. masterbike360

    T.Willey Guest

    You could do something like.

    (foreach item NewList
    (if (= (vl-filename-base DwgNmx) (substr item 1 (- (strlen item) 3))
    (progn
    (setq LastNum 01)
    (setq tmpNum (substr item (- (strlen item) 1)))
    (if (> tmpNum LastNum)
    (setq LastNum tmpNum)
    )
    )
    )
    )

    Where LastNum would be the highest number suffix of the drawing.

    Tim

    ps. Un-tested, written on the fly, but should get you going.
     
    T.Willey, Jan 11, 2005
    #2
  3. masterbike360

    T.Willey Guest

    Or maybe use this.

    (defun LastDwgNumber (DirPath DwgNumPrefix / DwgList DwgNum)
    ; ie. (LastDwgNumber "c:/temp" "test")
    ; Return the hightest number as a string or
    ; nil if no drawing by that name exist.
    ; Tested on drawing names formated like "test-01.dwg"

    (if (setq DwgList (vl-directory-files DirPath (strcat DwgNumPrefix "*.dwg")))
    (progn
    (setq DwgList (mapcar 'vl-filename-base DwgList))
    (setq DwgList (vl-sort DwgList '>))
    (setq DwgNum (substr (car DwgList) (- (strlen (car DwgList)) 1)))
    )
    )
    )

    Tim
     
    T.Willey, Jan 11, 2005
    #3
  4. Thaks for your input...the only thing is, I got the last version. What I whant, is to increase this value by one. 01 will become 02.

    Big thanks for your help...very appreciate.
    Simon
     
    masterbike360, Jan 11, 2005
    #4
  5. masterbike360

    T.Willey Guest

    After you get the last digit convert it to an interget, then add one.
    (setq NumVal (atoi <Your last digit in string format>))
    (setq NumVal (1+ NumVal))
    (if (< NumVal 10)
    (setq NumVal (strcat "0" (itoa NumVal)))
    (setq NumVal (itoa NumVal))
    )
    The if statement is added incase the number is less then 10, because if it is, it won't return it as 09 only 9, so I am adding a 0 to it to become 09. This should work, not test though.

    Tim
     
    T.Willey, Jan 11, 2005
    #5
  6. everything work perfectly!!!

    Thank you very much.
    Simon
     
    masterbike360, Jan 11, 2005
    #6
  7. masterbike360

    T.Willey Guest

    Happy to help, and glad it works for you.

    Tim
     
    T.Willey, Jan 11, 2005
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.