Author Topic: Incremental Autosaves  (Read 1771 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Incremental Autosaves
« on: June 04, 2020, 07:55:56 PM »
I am trying to setup code that will do incremental autosaves about every 5 minutes, right now I have turned off the reactor portion because it keeps saying too many arguments, not sure why, maybe someone can help me figure that out as well, but where the aSave function fails is at vl-file-copy, I have even tried typing in the full paths and they still fail, any ideas why? I just get a nil error, not exactly helpful.

Code: [Select]
;Code loosely based from several pieces of code at:
;http://www.theswamp.org/index.php?topic=4735.15
(vl-load-com)
(setq minutes 5
      DWGFolder (strcat (getvar "DWGPREFIX") "AutoSave\\")
      DWGFile (getvar "DWGNAME")
      MainFile (strcat DWGFolder DWGFile)
      IncCount 0
)
(if (not
       (vl-file-directory-p DWGFolder))
       (vl-mkdir (strcat DWGFolder))
   )
;test

;(if (not rxnAutoSave)
 ;(setq rxnAutoSave (vlr-editor-reactor nil '((:vlr-commandended     . aSave))))
;)

(defun c:aSave (/ AutoName)
    (if (= D1 nil)
        (setq D1 (getvar "DATE"))
    )
    (if (> (* (- (getvar "DATE") D1) 1440.0) minutes)
        (progn
            (princ (strcat "\nAutoSaving To:  " DWGFolder))
            (princ "\nPlease wait .... ")
            (setq IncCount (+ IncCount 1))
            (if (> IncCount 10)
                (setq IncCount 1)
            )
            (setq AutoName (strcat DWGFolder (rtos 0 2 IncCount) " - " DWGFile))
            (if (findfile AutoName)
                (vl-file-delete AutoName)
            )
            (vl-file-copy MainFile AutoName)
            (princ "\nAutoSave is now complete.")
        )
        (progn
            (princ "\nNot time yet")
        )
    )
)

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Incremental Autosaves
« Reply #1 on: June 04, 2020, 10:36:23 PM »
Why not use the inbuilt there is more than just time in the autosave function do a google. Stuff like percent save.
A man who never made a mistake never made anything

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Incremental Autosaves
« Reply #2 on: June 05, 2020, 03:16:40 AM »
The MainFile does not point to your DWG. You have added "AutoSave\\" to the path.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Incremental Autosaves
« Reply #3 on: June 05, 2020, 12:20:21 PM »
Why not use the inbuilt there is more than just time in the autosave function do a google. Stuff like percent save.
Because I need historic copies, for example someone is working on a drawing, saves and closes it, but realized they need one from 15 minutes before the file was saved.

To my knowledge nothing exists that keeps these copies and the routine isn't finished, it will also keep daily, weekly and monthly copies by the time I am done. Yes I know some of this is also done by our backup routines, but those aren't readily accessible to the user and it is becoming more of an issue as of late.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Incremental Autosaves
« Reply #4 on: June 05, 2020, 12:20:58 PM »
The MainFile does not point to your DWG. You have added "AutoSave\\" to the path.
Duh, I knew I was overlooking something simple, thank you.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Incremental Autosaves
« Reply #5 on: June 05, 2020, 12:53:56 PM »
I've been using this for many years. It saves files in dated folders in 15 minute increments on the users local computer. "C:\AutoCAD-BAK\2020.06.05\10-45\pathofdrawing\dwgname.dwg"
Code - Auto/Visual Lisp: [Select]
  1. (defun rjp-backupdwg (/ _date bd copyp d date dcp dp dwgp h m)
  2.   ;; RJP » 2019-05-10
  3.   (defun _date (f) (menucmd (strcat "M=$(edtime,$(getvar,date)," f ")")))
  4.   (cond ((and (= 1 (getvar 'dwgtitled) (getvar 'writestat))
  5.               (or (vl-file-directory-p (setq bd (strcat (getenv "homedrive") "\\AutoCAD-BAK\\")))
  6.                   (vl-mkdir bd)
  7.               )
  8.          )
  9.          (setq dp    (getvar 'dwgprefix)
  10.                date  (_date "YYYY.MO.DD/")
  11.                m     (itoa (abs (- (rem (setq m (atoi (_date "MM"))) 15) m)))
  12.                h     (strcat (_date "HH")
  13.                              "-"
  14.                              (if (= m "0")
  15.                                "0"
  16.                                ""
  17.                              )
  18.                              m
  19.                              "/"
  20.                      )
  21.                dcp   (strcat (vl-string-right-trim "." (substr (vl-string-translate "\\\"" "." dp) 4)) "/")
  22.                copyp (strcat bd date h dcp (getvar 'dwgname))
  23.                dwgp  (strcat dp (getvar 'dwgname))
  24.          )
  25.          (vl-mkdir (setq d (strcat bd date)))
  26.          (vl-mkdir (setq d (strcat d h)))
  27.          (vl-mkdir (setq d (strcat d dcp)))
  28.          (and (findfile copyp) (vl-file-delete copyp))
  29.          (and (vl-file-directory-p d) (vl-file-copy dwgp copyp))
  30.         )
  31.   )
  32.   (princ)
  33. )
« Last Edit: June 05, 2020, 12:57:50 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Pad

  • Bull Frog
  • Posts: 342
Re: Incremental Autosaves
« Reply #6 on: June 06, 2020, 10:23:48 AM »