Author Topic: save dwg as backup on open before its modified  (Read 5975 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: 7527
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: 7527
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: 7527
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: 7527
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