Jump to content
Baber62

Saving a file with rev date and timestamp

Recommended Posts

Baber62

I need to modify a LISP routine. Here's what it supposed to do:

 

1. save a CAD file with the Filename - Date - Rev00- Timestamp,

2. when it saved it should be saved in two locations, one being the working directory from which the drawing was opened and then in a folder called superseded within the working directory

3. each time it is saved the date - rev - timestamp change (note the rev number needs to be incremented by 1)

4. the previous version of the file in the working directory to be deleted completely

 

The story so far is that we have managed to get most of the above specifications to work except that it does not include rev number in the filename and doesn't update the current directory although it creates the superseded directory and all subsequent saves using the SAV.lsp are in the superseded directory.

 

Need assistance with one please ...

SAV.LSP

Share this post


Link to post
Share on other sites
hanhphuc

how about using FIELD object timestamp?

or

if block attribute can try this suggestion?

Share this post


Link to post
Share on other sites
pBe

What is the reference for the Revision number then?

Share this post


Link to post
Share on other sites
BIGAL

Like wise you can make use a field "filename" as part of your title block we do this and find it very useful. Like Pbe changing REV we only do if required not each save ?

Share this post


Link to post
Share on other sites
Lee Mac

Here is a revised version of your current code as a better starting point:

(defun c:sav ( / cpy sub )
   (setq sub "superseded") ;; Subdirectory
   (cond
       (   (zerop (getvar 'dwgtitled))
           (princ "\nCurrent drawing is unsaved.")
       )
       (   (not (or (findfile (setq sub (strcat (getvar 'dwgprefix) sub))) (vl-mkdir sub)))
           (princ (strcat "\nUnable to create directory " sub))
       )
       (   (progn
               (princ "\nSaving current drawing...")
               (command "_.qsave")
               (not 
                   (vl-file-copy (strcat (getvar 'dwgprefix) (getvar 'dwgname))
                       (setq cpy 
                           (strcat sub "\\"
                               (vl-filename-base (getvar 'dwgname)) "-"
                               (menucmd "m=$(edtime,0,YYYYMODD-HHMMSS)") 
                               (vl-filename-extension (getvar 'dwgname))
                           )
                       )
                   )
               )
           )
           (princ (strcat "\nUnable to copy drawing to " cpy))
       )
       (   (princ (strcat "\nDrawing copied to " cpy)))
   )
   (princ)
)

 

Could you clarify the following:

 

  • Should the filename of the active drawing be changed to include the revision, date & timestamp?
  • Should the filename format be XXXX-YYYYMODD-REV00-HHMMSS.dwg (where XXXX is the original filename)?

Share this post


Link to post
Share on other sites
Baber62

pBe: The reference for the revision number should be starting from 00 then incremented by 1 on the saves thereafter

 

BIGAL: I tend to do numerous saves throughout the day, however, it's only at the end of the day that I intend to use this routine. Also this routine can be used as a management tool in making sure that when the next person who opens the drawing will have the latest drawing to open from the current drawing folder. As you know people copy drawings on their pen drives and then copy them back into the folders thereby losing x-references and completely messing up the drawings.

 

Lee Mac:

 

Yes the filename of the active drawing needs to be changed to include revision date and timestamp.

 

Yes the filename format should be XXXX-YYYYMODD-REV00-HHMM.dwg (where XXXX is the original filename) (only just the hhmm required rather than the ss also could the date be in the following format "31 Mar 2015" with out the "-" in between)

 

thanks guys appreciated

Share this post


Link to post
Share on other sites
BIGAL
on their pen drives
they should be horse whipped for breaking standards :twisted:

Share this post


Link to post
Share on other sites
Baber62

@BIGAL

everyone it seems has their own way of doing drawings ... that's when thing start to fail. If it were standardized across the industry then no problem. For example in the company I work for (who shall for this purpose remain nameless) we have one manager who gives the same drawing to several different people to do, but as you can gather none of these drawing have any x-refs as they have been inserted as blocks and exploded, so no one individual can be held responsible. That's why I need this routine so this way I can at least retain some sanity in this insane world of ours!!

Share this post


Link to post
Share on other sites
Baber62

@LeeMac

Lee Mac:

 

Please can you assist when you have time ... thanks in advance

Edited by Baber62

Share this post


Link to post
Share on other sites
Lee Mac

Try something along the lines of:

([color=BLUE]defun[/color] c:sav ( [color=BLUE]/[/color] cpy dwg rev sub )
   ([color=BLUE]setq[/color] sub [color=MAROON]"superseded"[/color] [color=GREEN];; Subdirectory[/color]
         dwg ([color=BLUE]vl-filename-base[/color] ([color=BLUE]getvar[/color] 'dwgname))
   )
   ([color=BLUE]cond[/color]
       (   ([color=BLUE]zerop[/color] ([color=BLUE]getvar[/color] 'dwgtitled))
           ([color=BLUE]princ[/color] [color=MAROON]"\nCurrent drawing is unsaved."[/color])
       )
       (   ([color=BLUE]not[/color] ([color=BLUE]or[/color] ([color=BLUE]findfile[/color] ([color=BLUE]setq[/color] sub ([color=BLUE]strcat[/color] ([color=BLUE]getvar[/color] 'dwgprefix) sub))) ([color=BLUE]vl-mkdir[/color] sub)))
           ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nUnable to create directory "[/color] sub))
       )
       (   [color=BLUE]t[/color]
           ([color=BLUE]cond[/color]
               (   ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] dwg) [color=MAROON]"*-########-REV##-####"[/color])
                   ([color=BLUE]if[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]setq[/color] rev ([color=BLUE]itoa[/color] ([color=BLUE]1+[/color] ([color=BLUE]atoi[/color] ([color=BLUE]substr[/color] dwg ([color=BLUE]-[/color] ([color=BLUE]strlen[/color] dwg) 6) 2))))) [color=MAROON]"#"[/color])
                       ([color=BLUE]setq[/color] rev ([color=BLUE]strcat[/color] [color=MAROON]"0"[/color] rev))
                   )
                   ([color=BLUE]command[/color] [color=MAROON]"_.saveas"[/color] [color=MAROON]""[/color]
                       (LM:uniquefilename
                           ([color=BLUE]strcat[/color]
                               ([color=BLUE]getvar[/color] 'dwgprefix)
                               ([color=BLUE]substr[/color] dwg 1 ([color=BLUE]-[/color] ([color=BLUE]strlen[/color] dwg) 20))
                               ([color=BLUE]menucmd[/color] ([color=BLUE]strcat[/color] [color=MAROON]"m=$(edtime,0,-YYYYMODD-REV"[/color] rev [color=MAROON]"-HHMM)"[/color]))
                           )
                           [color=MAROON]".dwg"[/color]
                       )
                   )
               )
               (   ([color=BLUE]command[/color] [color=MAROON]"_.saveas"[/color] [color=MAROON]""[/color]
                       (LM:uniquefilename
                           ([color=BLUE]strcat[/color] ([color=BLUE]getvar[/color] 'dwgprefix) dwg ([color=BLUE]menucmd[/color] [color=MAROON]"m=$(edtime,0,-YYYYMODD-REV00-HHMM)"[/color]))
                           [color=MAROON]".dwg"[/color]
                       )
                   )
               )
           )
           ([color=BLUE]vl-file-rename[/color]
               ([color=BLUE]strcat[/color] ([color=BLUE]getvar[/color] 'dwgprefix) dwg [color=MAROON]".dwg"[/color])
               ([color=BLUE]strcat[/color] sub [color=MAROON]"\\"[/color] dwg [color=MAROON]".dwg"[/color])
           )
       )
   )
   ([color=BLUE]princ[/color])
)

[color=GREEN];; Unique Filename  -  Lee Mac[/color]
[color=GREEN];; Returns a unique filename for a given path & file extension[/color]

([color=BLUE]defun[/color] LM:uniquefilename ( pth ext [color=BLUE]/[/color] fnm tmp )
   ([color=BLUE]if[/color] ([color=BLUE]findfile[/color] ([color=BLUE]setq[/color] fnm ([color=BLUE]strcat[/color] pth ext)))
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] tmp 1)
           ([color=BLUE]while[/color] ([color=BLUE]findfile[/color] ([color=BLUE]setq[/color] fnm ([color=BLUE]strcat[/color] pth [color=MAROON]"("[/color] ([color=BLUE]itoa[/color] ([color=BLUE]setq[/color] tmp ([color=BLUE]1+[/color] tmp))) [color=MAROON]")"[/color] ext))))
       )
   )
   fnm
)

([color=BLUE]princ[/color])

Share this post


Link to post
Share on other sites
Baber62

@Lee Mac,

 

Thanks for that the routine works fine. Only requires a slight modification, when run the command needs to save to both locations i.e. say it renames the current drawing to "...Rev02..." it should also save the Rev02 in the superseded directory.

 

Thanks for your time and assistance.

Share this post


Link to post
Share on other sites
Lee Mac
Only requires a slight modification, when run the command needs to save to both locations i.e. say it renames the current drawing to "...Rev02..." it should also save the Rev02 in the superseded directory.

 

Certainly possible, but I'm unsure why you would want this behaviour since the old issue will already be moved to the superseded directory when the current drawing is up-issued.

Share this post


Link to post
Share on other sites
Baber62

@ LeeMac,

 

Reason is that I the macro I have in visual basic saves the current edition of the file in two locations,(in the superseded and current directory) then any changes made since the last time the file was used can be traced. Also when you start on say the next day, you start from the same version as stored in the superseded directory.

Share this post


Link to post
Share on other sites
Lee Mac
Reason is that the macro I have in visual basic saves the current edition of the file in two locations, (in the superseded and current directory) then any changes made since the last time the file was used can be traced. Also when you start on say the next day, you start from the same version as stored in the superseded directory.

 

Currently the program will save the active drawing using the new revision number & timestamp, and will move the original to the superseded directory - therefore any changes made between the superseded revision & the current revision could be traced by comparing the two files.

 

When you start working on the file the following day, you would be working from the single most recent revision of the drawing; by saving the drawing in both places, there is no longer a single master version.

Share this post


Link to post
Share on other sites
Baber62

LeeMac,

 

You're assumptions are correct and your help appreciated.

 

Thanks for a wonderful brilliant routine!!! :notworthy:

Edited by Baber62
misspelling

Share this post


Link to post
Share on other sites
Lee Mac

You're most welcome Baber, happy to help :)

Share this post


Link to post
Share on other sites
Baber62

Hi Lee need your kind assistance with this one again. The revision number works okay up to 100 then when a subsequent save is made the file name changes to something like this "20mph Review-20170205-REV100-1412-20170205-REV00-1412.dwg" It seems to have added the date revision and timestamp again. Please can you look at the routine and adjust it so that it can handle three figures in the revision number.

Thanks for looking into this.

Share this post


Link to post
Share on other sites
Lee Mac

Please try the following modification:

([color=BLUE]defun[/color] c:sav ( [color=BLUE]/[/color] cpy dwg lst rev sub )
   ([color=BLUE]setq[/color] sub [color=MAROON]"superseded"[/color] [color=GREEN];; Subdirectory[/color]
         dwg ([color=BLUE]vl-filename-base[/color] ([color=BLUE]getvar[/color] 'dwgname))
   )
   ([color=BLUE]cond[/color]
       (   ([color=BLUE]zerop[/color] ([color=BLUE]getvar[/color] 'dwgtitled))
           ([color=BLUE]princ[/color] [color=MAROON]"\nCurrent drawing is unsaved."[/color])
       )
       (   ([color=BLUE]not[/color] ([color=BLUE]or[/color] ([color=BLUE]findfile[/color] ([color=BLUE]setq[/color] sub ([color=BLUE]strcat[/color] ([color=BLUE]getvar[/color] 'dwgprefix) sub))) ([color=BLUE]vl-mkdir[/color] sub)))
           ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nUnable to create directory "[/color] sub))
       )
       (   [color=BLUE]t[/color]
           ([color=BLUE]cond[/color]
               (   ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] dwg) [color=MAROON]"*-########-REV#*-####"[/color])
                   ([color=BLUE]setq[/color] lst ([color=BLUE]reverse[/color] (LM:str->lst dwg [color=MAROON]"-"[/color]))
                         rev ([color=BLUE]strcat[/color] [color=MAROON]"00"[/color] ([color=BLUE]itoa[/color] ([color=BLUE]1+[/color] ([color=BLUE]atoi[/color] ([color=BLUE]substr[/color] ([color=BLUE]cadr[/color] lst) 4)))))
                   )
                   ([color=BLUE]command[/color] [color=MAROON]"_.saveas"[/color] [color=MAROON]""[/color]
                       (LM:uniquefilename
                           ([color=BLUE]strcat[/color]
                               ([color=BLUE]getvar[/color] 'dwgprefix)
                               (LM:lst->str ([color=BLUE]reverse[/color] ([color=BLUE]cdddr[/color] lst)) [color=MAROON]"-"[/color])
                               ([color=BLUE]menucmd[/color] ([color=BLUE]strcat[/color] [color=MAROON]"m=$(edtime,0,-YYYYMODD-REV"[/color] ([color=BLUE]substr[/color] rev ([color=BLUE]-[/color] ([color=BLUE]strlen[/color] rev) 2)) [color=MAROON]"-HHMM)"[/color]))
                           )
                           [color=MAROON]".dwg"[/color]
                       )
                   )
               )
               (   ([color=BLUE]command[/color] [color=MAROON]"_.saveas"[/color] [color=MAROON]""[/color]
                       (LM:uniquefilename
                           ([color=BLUE]strcat[/color] ([color=BLUE]getvar[/color] 'dwgprefix) dwg ([color=BLUE]menucmd[/color] [color=MAROON]"m=$(edtime,0,-YYYYMODD-REV000-HHMM)"[/color]))
                           [color=MAROON]".dwg"[/color]
                       )
                   )
               )
           )
           ([color=BLUE]vl-file-rename[/color]
               ([color=BLUE]strcat[/color] ([color=BLUE]getvar[/color] 'dwgprefix) dwg [color=MAROON]".dwg"[/color])
               ([color=BLUE]strcat[/color] sub [color=MAROON]"\\"[/color] dwg [color=MAROON]".dwg"[/color])
           )
       )
   )
   ([color=BLUE]princ[/color])
)

[color=GREEN];; List to String  -  Lee Mac[/color]
[color=GREEN];; Concatenates each string in a supplied list, separated by a given delimiter[/color]
[color=GREEN];; lst - [lst] List of strings to concatenate[/color]
[color=GREEN];; del - [str] Delimiter string to separate each item[/color]

([color=BLUE]defun[/color] LM:lst->str ( lst del )
   ([color=BLUE]if[/color] ([color=BLUE]cdr[/color] lst)
       ([color=BLUE]strcat[/color] ([color=BLUE]car[/color] lst) del (LM:lst->str ([color=BLUE]cdr[/color] lst) del))
       ([color=BLUE]car[/color] lst)
   )
)

[color=GREEN];; String to List  -  Lee Mac[/color]
[color=GREEN];; Separates a string using a given delimiter[/color]
[color=GREEN];; str - [str] String to process[/color]
[color=GREEN];; del - [str] Delimiter by which to separate the string[/color]
[color=GREEN];; Returns: [lst] List of strings[/color]

([color=BLUE]defun[/color] LM:str->lst ( str del [color=BLUE]/[/color] pos )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] pos ([color=BLUE]vl-string-search[/color] del str))
       ([color=BLUE]cons[/color] ([color=BLUE]substr[/color] str 1 pos) (LM:str->lst ([color=BLUE]substr[/color] str ([color=BLUE]+[/color] pos 1 ([color=BLUE]strlen[/color] del))) del))
       ([color=BLUE]list[/color] str)
   )
)

[color=GREEN];; Unique Filename  -  Lee Mac[/color]
[color=GREEN];; Returns a unique filename for a given path & file extension[/color]

([color=BLUE]defun[/color] LM:uniquefilename ( pth ext [color=BLUE]/[/color] fnm tmp )
   ([color=BLUE]if[/color] ([color=BLUE]findfile[/color] ([color=BLUE]setq[/color] fnm ([color=BLUE]strcat[/color] pth ext)))
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] tmp 1)
           ([color=BLUE]while[/color] ([color=BLUE]findfile[/color] ([color=BLUE]setq[/color] fnm ([color=BLUE]strcat[/color] pth [color=MAROON]"("[/color] ([color=BLUE]itoa[/color] ([color=BLUE]setq[/color] tmp ([color=BLUE]1+[/color] tmp))) [color=MAROON]")"[/color] ext))))
       )
   )
   fnm
)

([color=BLUE]princ[/color])

Share this post


Link to post
Share on other sites
Baber62

Thanks Lee, indebted to you for being a life saver :D

Share this post


Link to post
Share on other sites
supertxull
Please try the following modification:

Hi, I need something similar and I thought I could get it but certainly I can't do it.

I want to make a command to save a copy of the current drawing in a subdirectory and rename it sequentially (Drawing1.dwg, Drawing1 (2) .dwg, Drawing1 (3) .dwg ...). It would not be necessary to add a date to the file name but the revision number would be unlimited (or at least very high (3 digits)). You can help?

Thank you very much and sorry for my english :-$

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...