Author Topic: save dwg as backup on open before its modified  (Read 5889 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
save dwg as backup on open before its modified
« on: September 11, 2014, 11:02:30 AM »
I have a few functions that save dwg before you close it and auto saves
however is it possible to save a dwg as soon as its opened? maybe with a reactor?

what im planning is a save function that will save a dwg to a backup directory as an original so that if something were to go wrong (IE: if entities were mistakenly deleted and dwg was saved  :whistling:) that the original dwg would still be intact.

thoughts?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: save dwg as backup on open before its modified
« Reply #1 on: September 11, 2014, 11:07:42 AM »
Autocad automatically creates a backup of the drawing when you save, so you can always recover the last version .. asuming of course that you don't save the drawing every 5 minutes or something and overwrite the backup drawing.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ronjonp

  • Needs a day job
  • Posts: 7526
Re: save dwg as backup on open before its modified
« Reply #2 on: September 11, 2014, 11:10:08 AM »
...
however is it possible to save a dwg as soon as its opened? maybe with a reactor?
...
You don't need a reactor, just add something like so to your startup:
Code - Auto/Visual Lisp: [Select]
  1.   (strcat (getvar 'dwgprefix) (getvar 'dwgname))
  2.   (strcat "C:\\MYINITIALBACKUPPATH\\" (getvar 'dwgname))
  3. )

You'll have to make sure that the backup directory exists prior to copying though.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3770
Re: save dwg as backup on open before its modified
« Reply #3 on: September 11, 2014, 11:35:29 AM »
...
however is it possible to save a dwg as soon as its opened? maybe with a reactor?
...
You don't need a reactor, just add something like so to your startup:
Code - Auto/Visual Lisp: [Select]
  1.   (strcat (getvar 'dwgprefix) (getvar 'dwgname))
  2.   (strcat "C:\\MYINITIALBACKUPPATH\\" (getvar 'dwgname))
  3. )

You'll have to make sure that the backup directory exists prior to copying though.

You'll also have to check that the target file name does not already exist, and/or is successfully deleted:

More on vl-File-Copy: http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-12910252-217C-427D-8874-1323611FA74C


... Unless you're going to name the target accordingly with date/time, etc.

Code - Auto/Visual Lisp: [Select]
  1. (strcat "C:\\MYINITIALBACKUPPATH\\"
  2.         (vl-filename-base dwgName)
  3.         "_"
  4.         (menucmd "M=$(edtime,$(getvar,date),YYYY-MO-DD)")
  5.         ".dwg"
  6. )
  7.  
"How we think determines what we do, and what we do determines what we get."

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: save dwg as backup on open before its modified
« Reply #4 on: September 11, 2014, 11:43:14 AM »
... and you will need to verify that the drawing is not a new drawing that has never been saved to disk.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ronjonp

  • Needs a day job
  • Posts: 7526
Re: save dwg as backup on open before its modified
« Reply #5 on: September 11, 2014, 11:50:01 AM »
Both excellent suggestions. Perhaps this would work.  :)
RJP-XCOPY
XCOPY Switches
Code - Auto/Visual Lisp: [Select]
  1. (if (= 1 (getvar 'dwgtitled))
  2.   (rjp-xcopy (getvar 'dwgprefix) (getvar 'dwgname) "C:\\MyInitialBackup\\" "/d/c/i/k/r/y/q")
  3. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3770
Re: save dwg as backup on open before its modified
« Reply #6 on: September 11, 2014, 12:09:40 PM »
Both excellent suggestions. Perhaps this would work.  :)
RJP-XCOPY
XCOPY Switches
Code - Auto/Visual Lisp: [Select]
  1. (if (= 1 (getvar 'dwgtitled))
  2.   (rjp-xcopy (getvar 'dwgprefix) (getvar 'dwgname) "C:\\MyInitialBackup\\" "/d/c/i/k/r/y/q")
  3. )

*Sigh*... What, no bit-coded switches? :roll:



 :-P  :-D
"How we think determines what we do, and what we do determines what we get."

ronjonp

  • Needs a day job
  • Posts: 7526
Re: save dwg as backup on open before its modified
« Reply #7 on: September 11, 2014, 12:21:47 PM »
What is this "bitcode" you speak of ?  :whistling:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3770
Re: save dwg as backup on open before its modified
« Reply #8 on: September 11, 2014, 12:24:30 PM »
... and you will need to verify that the drawing is not a new drawing that has never been saved to disk.

Perhaps I've misunderstood the thread title, but the OP seems to be attempting to create a backup immediately after opening an existing drawing (not creating a new drawing).

My $0.02
"How we think determines what we do, and what we do determines what we get."

ronjonp

  • Needs a day job
  • Posts: 7526
Re: save dwg as backup on open before its modified
« Reply #9 on: September 11, 2014, 12:33:16 PM »
We'll let him chime in .. perhaps we're both WAAAYYYY off the mark.  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: save dwg as backup on open before its modified
« Reply #10 on: September 11, 2014, 12:37:19 PM »
Isn't all this moot?  This runs *after* the drawing is opened which can itself modify the content.  Might be more productive to create a backup on closing the drawing.  Or just use regular backups.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

andrew_nao

  • Guest
Re: save dwg as backup on open before its modified
« Reply #11 on: September 11, 2014, 01:19:06 PM »
... and you will need to verify that the drawing is not a new drawing that has never been saved to disk.

Perhaps I've misunderstood the thread title, but the OP seems to be attempting to create a backup immediately after opening an existing drawing (not creating a new drawing).

My $0.02

yes i want to save it, or copy it would probably be best, to another directory as an original file so i can then continue to modify that same dwg.
i only need 1 instance of the dwg to be saved though. if i copy the file, it shouldnt overwrite if the file exists, correct?

andrew_nao

  • Guest
Re: save dwg as backup on open before its modified
« Reply #12 on: September 11, 2014, 01:22:19 PM »
Isn't all this moot?  This runs *after* the drawing is opened which can itself modify the content.  Might be more productive to create a backup on closing the drawing.  Or just use regular backups.

thats why i want to back it up, copy it, save it, to another directory so its not modified and will be labeled "original" while still opening the dwg to be modified.

just looking for ideas and thoughts and appreciate the feedback

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: save dwg as backup on open before its modified
« Reply #13 on: September 11, 2014, 01:56:32 PM »
... and you will need to verify that the drawing is not a new drawing that has never been saved to disk.

Perhaps I've misunderstood the thread title, but the OP seems to be attempting to create a backup immediately after opening an existing drawing (not creating a new drawing).

My $0.02

You are correct, however, the solution was proposed to be added to the startup lisp ... the same startup lisp that runs regardless of whether you are opening a drawing or starting a new blank drawing ...

this is why I get paid the big bucks ;-)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

GDF

  • Water Moccasin
  • Posts: 2081
Re: save dwg as backup on open before its modified
« Reply #14 on: September 11, 2014, 02:45:09 PM »
Code: [Select]

;|
Well copy the below code into your acaddoc.lsp and then get used to
typing "BAK" before you start any major (or minor for that matter)
changes to your drawing.  It will create a /BackUp directory, if not
already present, and a file with the date and time appended to the
drawing name: C:/MyProject/X_Site.dwg would be saved as
C:/MyProject/BackUp/X_Site-2006.03.30.18.32.39.dwg.
|;
;;;James Buzbee
;;;http://www.theswamp.org/index.php?topic=9453.0
(defun c:bak  (/ file dirs dir)
  (setq dirs(vl-directory-files(getvar "dwgprefix") nil -1))
  (if(not(or (member "backup" dirs)(member "archive" dirs)(member "archive" dirs)))
    (setq dir(vl-mkdir (strcat (getvar "dwgprefix")"archive")))
    (setq dir t)
    )
  (if dir
    (progn
  (setq file (strcat
       (getvar "dwgprefix")"archive\\"
       (vl-filename-base (getvar "dwgname")) "_"
       ;;(menucmd "M=$(edtime,$(getvar,date),YYYY.MO.DD.HH.MM.SS)")
               (menucmd "M=$(edtime,$(getvar,date),MO-DD-YYYY_HH.MM)")
       ".dwg"))
  (while (findfile file)
    (setq file (strcat
       (getvar "dwgprefix")"archive\\"
       (vl-filename-base (getvar "dwgname")) "_"
       ;;(menucmd "M=$(edtime,$(getvar,date),YYYY.MO.DD.HH.MM.SS)")
               (menucmd "M=$(edtime,$(getvar,date),MO-DD-YYYY_HH.MM)")
       ".dwg")))
  (if file
    (command "save" file))))
  (princ file)(princ))

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7526
Re: save dwg as backup on open before its modified
« Reply #15 on: September 11, 2014, 03:29:55 PM »
I was not sure how Andrew was going to implement the solution just throwing ideas out there. My backup saves files in 15 minute increments while working. Has worked well for me.


Then there was THIS lisp I wrote way back when that created a folder called 'SUPERSCEDE' and copied the current drawing and xrefs into it.


Have fun !

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3770
Re: save dwg as backup on open before its modified
« Reply #16 on: September 11, 2014, 03:48:28 PM »
... and you will need to verify that the drawing is not a new drawing that has never been saved to disk.

Perhaps I've misunderstood the thread title, but the OP seems to be attempting to create a backup immediately after opening an existing drawing (not creating a new drawing).

My $0.02

You are correct, however, the solution was proposed to be added to the startup lisp ... the same startup lisp that runs regardless of whether you are opening a drawing or starting a new blank drawing ...

this is why I get paid the big bucks ;-)

Big bucks you may be paid, but where I previously state that need not be considered, you cannot cite. :angel:

"How we think determines what we do, and what we do determines what we get."

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: save dwg as backup on open before its modified
« Reply #17 on: September 11, 2014, 03:52:04 PM »
... and you will need to verify that the drawing is not a new drawing that has never been saved to disk.

Perhaps I've misunderstood the thread title, but the OP seems to be attempting to create a backup immediately after opening an existing drawing (not creating a new drawing).

My $0.02

You are correct, however, the solution was proposed to be added to the startup lisp ... the same startup lisp that runs regardless of whether you are opening a drawing or starting a new blank drawing ...

this is why I get paid the big bucks ;-)

Big bucks you may be paid, but where I previously state that need not be considered, you cannot cite. :angel:



WUT?

Who said anything about you? I was referring to the very first solution where it plainly says to add it to the startup. If you misunderstood, I cannot help that.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: save dwg as backup on open before its modified
« Reply #18 on: September 11, 2014, 03:56:45 PM »
Why not simply use Ron's code to make a copy each time the DWG is saved??  It's essentially the same as making a copy of it before it's modified, isn't it??  I mean, the file that is copied (whether it's after a save or before an open) is the same thing.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

BlackBox

  • King Gator
  • Posts: 3770
Re: save dwg as backup on open before its modified
« Reply #19 on: September 11, 2014, 04:02:36 PM »
... and you will need to verify that the drawing is not a new drawing that has never been saved to disk.

Perhaps I've misunderstood the thread title, but the OP seems to be attempting to create a backup immediately after opening an existing drawing (not creating a new drawing).

My $0.02

You are correct, however, the solution was proposed to be added to the startup lisp ... the same startup lisp that runs regardless of whether you are opening a drawing or starting a new blank drawing ...

this is why I get paid the big bucks ;-)

Big bucks you may be paid, but where I previously state that need not be considered, you cannot cite. :angel:



WUT?

Who said anything about you? I was referring to the very first solution where it plainly says to add it to the startup. If you misunderstood, I cannot help that.

You did. :wink:
"How we think determines what we do, and what we do determines what we get."

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: save dwg as backup on open before its modified
« Reply #20 on: September 11, 2014, 05:57:06 PM »
Here's a simple one I keep in my startup. If the file already exists (for the current day), it will not be copied over again, which is what I wanted.
I should change it to use a copy method other than vl-file-copy, just so I the original file edit date won't be changed, but it's never been a big deal for what this has been there for.

Code: [Select]
((lambda (/ path)
   (if (not (wcmatch (strcase (getvar 'DWGNAME)) "DRAWING*"))
     (progn
       (vl-mkdir (setq path "c:\\dwgBackup"))
       (vl-mkdir (setq path (strcat path "\\" (menucmd "M=$(edtime,$(getvar,date),YYYY.M.DD)") "\\")))
       (vl-file-copy (strcat (getvar 'DWGPREFIX) (getvar 'DWGNAME)) (strcat path (getvar 'DWGNAME)))
     )
   )
 )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

BlackBox

  • King Gator
  • Posts: 3770
Re: save dwg as backup on open before its modified
« Reply #21 on: September 11, 2014, 06:49:59 PM »
I do something very similar in my VOID routine, which I used to make a dated copy of a drawing prior to making major design changes. I also have a routine which allows me to quickly 'step' through one or more previously created void copies (which are relative pathed).

Also, always good to see you in the forums AT. :beer:
"How we think determines what we do, and what we do determines what we get."

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: save dwg as backup on open before its modified
« Reply #22 on: September 12, 2014, 12:03:55 PM »
... and you will need to verify that the drawing is not a new drawing that has never been saved to disk.

Perhaps I've misunderstood the thread title, but the OP seems to be attempting to create a backup immediately after opening an existing drawing (not creating a new drawing).

My $0.02

You are correct, however, the solution was proposed to be added to the startup lisp ... the same startup lisp that runs regardless of whether you are opening a drawing or starting a new blank drawing ...

this is why I get paid the big bucks ;-)

Big bucks you may be paid, but where I previously state that need not be considered, you cannot cite. :angel:



WUT?

Who said anything about you? I was referring to the very first solution where it plainly says to add it to the startup. If you misunderstood, I cannot help that.

You did. :wink:

WUT? X2
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: save dwg as backup on open before its modified
« Reply #23 on: September 13, 2014, 09:27:35 AM »
Code: [Select]
(if (not (wcmatch (strcase (getvar 'DWGNAME)) "DRAWING*"))

FWIW, the above could be:
Code: [Select]
(if (= 1 (getvar 'dwgtitled))
To account for the possibility that a saved drawing starts with 'DRAWING...'

ChrisCarlson

  • Guest
Re: save dwg as backup on open before its modified
« Reply #24 on: September 15, 2014, 08:29:14 AM »
Edited

« Last Edit: September 15, 2014, 01:15:02 PM by ChrisCarlson »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: save dwg as backup on open before its modified
« Reply #25 on: September 15, 2014, 08:38:25 AM »
Code: [Select]
(if (not (wcmatch (strcase (getvar 'DWGNAME)) "DRAWING*"))

FWIW, the above could be:
Code: [Select]
(if (= 1 (getvar 'dwgtitled))
To account for the possibility that a saved drawing starts with 'DRAWING...'
I always forget about that variable. Thanks.
Granted, I seriously hope people aren't naming files starting with "Drawing".
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

andrew_nao

  • Guest
Re: save dwg as backup on open before its modified
« Reply #26 on: September 15, 2014, 09:45:17 AM »
wow some good ideas in here.
the thought i was having was just to have a backup of a dwg like alajt's suggestion.
just 1 copy no overwrite, no delete and recopy. just 1 copy as "original".
that is very simple code too, i thought it would be a bit more complicated to implement.

appreciate everyones feedback

ChrisCarlson

  • Guest
Re: save dwg as backup on open before its modified
« Reply #27 on: September 15, 2014, 01:18:38 PM »
Corrected the batch file

Code: [Select]
@ECHO OFF
SET _params=%*
CALL :sub "%_params%" 
:sub
ECHO %~nx1
set folder=C:\AutoCAD_Originals
set odate=%date:~4,2%_%date:~7,2%_%date:~10,4%
copy %~nx1 "%FOLDER%\%~n1-%ODATE%.dwg"
start %~nx1
exit

Code: [Select]
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Drawing Backup]
"Position"="Top"
"Extended"=""
[HKEY_CLASSES_ROOT\*\shell\Drawing Backup\command]
@="cmd.exe /T:17 /K C:\\AutoCAD_Originals "%1""

Simply right click and open the file you want with Drawing Backup.

Does time stamps matter? I know going through lisp changes the last edit time stamp within the file.