| Author |
Message |
masterbike360
Guest
|
Posted:
Tue Jan 11, 2005 7:27 pm Post subject:
Increase a number (01)->(02) |
|
|
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
|
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Tue Jan 11, 2005 9:25 pm Post subject:
Re: List HELP... |
|
|
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. |
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Tue Jan 11, 2005 10:13 pm Post subject:
Re: List HELP... |
|
|
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
|
|
| Back to top |
|
 |
masterbike360
Guest
|
Posted:
Tue Jan 11, 2005 11:06 pm Post subject:
Re: List HELP... |
|
|
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 |
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Tue Jan 11, 2005 11:11 pm Post subject:
Re: List HELP... |
|
|
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 |
|
| Back to top |
|
 |
masterbike360
Guest
|
Posted:
Tue Jan 11, 2005 11:43 pm Post subject:
Re: List HELP... |
|
|
everything work perfectly!!!
Thank you very much.
Simon |
|
| Back to top |
|
 |
T.Willey
Guest
|
Posted:
Tue Jan 11, 2005 11:49 pm Post subject:
Re: List HELP... |
|
|
Happy to help, and glad it works for you.
Tim |
|
| Back to top |
|
 |
|
|
|
|