CoCreate User Forum

CoCreate User Forum (https://www.cocreateusers.org/forum/index.php)
-   Customization (https://www.cocreateusers.org/forum/forumdisplay.php?f=12)
-   -   Super Fast Autosave (https://www.cocreateusers.org/forum/showthread.php?t=8322)

gmatelich 05-02-2018 01:20 PM

Super Fast Autosave
 
I've been manually testing a much faster method of autosave, though admittedly it's currently much less user friendly. For testing I turn on autosave, with the 'ask before save' option; when it asks, I say no, then use file - save functionality. I'd like to take the next step in automating this; can someone help clean up my code (I'm still more of an ME Macro Language guy...) ? I'd like to get to the point that I can set two buttons in my toolbar to click these after saying no to autosave.
Code:

(in-package :valve)
(use-package :oli)
(defvar *AutoSaveIncrement* 1)                                                                                                                                                                                ;Loop counter
(defvar *AutoSaveNumberOfIncrements* 2)                                                                                                                                                                ;How many backups do you want?
(unless (sd-directory-p (format nil "~AAutosave" (sd-inq-temp-dir)))                                                                                                ;Check if an autosave directory exists in the user's temp directoy
  (sd-make-directory (format nil "~AAutosave" (sd-inq-temp-dir)))                                                                                                        ;Make Autosave directory
)

(defun AutoSaveBaseline
  (defvar *AutoSaveBaseLocation* (format nil "~AAutosave/~A" (sd-inq-temp-dir) (get-universal-time)))                                ;Establish autosave location
  (sd-display-alert "Beginning Autosave" :icon :info :auto-close-time 5)                                                                                        ;Popup toast warning user what's up
  (sd-with-current-working-directory AutoSaveBaseLocation                                                                                                                        ;Remember CWD, change dir, run these things, revert to CWD
    (save_sd :OVERWRITE :all_at_top :TOP_LEVEL_INSTANCE_FILES :YES :DIRECTORY complete)                                                                ;Save all items using .sd format
    (sd-display-alert (+ "Autosaved to " AutoSaveBaseLocation) :icon :info :auto-close-time 5)                                                ;Popup toast showing location saved to
    (sd-copy-file AutoSaveBaseLocation (+ AutoSaveBaseLocation "BaseCopy"))                                                                                        ;Capture fallback copy of baseline save
; actually I think I want something like this: (oli:sd-sys-background-job "xcopy C:\\Users\\gregm\\Documents\\AutosaveTest\\20180412a %temp%\\20180412ab\\")
  )
)
 
(defun AutoSaveIncremental
  (oli:sd-display-alert "Beginning Autosave" :icon :info :auto-close-time 1)                                                                                ;Popup toast warning user what's up
  (sd-with-current-working-directory AutoSaveBaseLocation                                                                                                                        ;Remember CWD, change dir, run these things, revert to CWD
    (save_sd_modified :OVERWRITE :all_at_top :TOP_LEVEL_INSTANCE_FILES :YES :DIRECTORY AutoSaveBaseLocation complete) ;Save all modified items - super fast
    (oli:sd-display-alert (+ "AutoSave to " AutoSaveBaseLocation) :icon :info :auto-close-time 5)                                        ;Popup toast showing location saved to
    (oli:sd-copy-file AutoSaveBaseLocation (+ AutoSaveBaseLocation "_" AutoSaveIncrement))                                                        ;Capture fallback copy of incremental save
  )       
  (if (= AutoSaveIncrement AutoSaveNumberOfIncrements)                                                                                                                                ;Loop to capture fallback increments
    (defvar *AutoSaveIncrement* 1)                                                                                                                                                                        ;Reset to 1
        (+ *AutoSaveIncrement* 1)                                                                                                                                                                                ;Increment by 1
  )       
)

Just doing a "baseline" save instead of the standard autosave, is a great time saver, since I don't have to wait for the package file to zip (why don't they do that in the background?).

Shaba 05-03-2018 03:55 AM

Re: Super Fast Autosave
 
interesting.
This a woking code?
My lisp skill is very poor

gmatelich 05-04-2018 09:53 AM

Re: Super Fast Autosave
 
No, not yet working code :-(

gmatelich 05-08-2018 08:56 AM

Re: Super Fast Autosave
 
Getting closer I think:

Code:

(in-package :valve)
(use-package :oli)
(sd-display-alert "Loading Autosave" :icon :info :auto-close-time 5)
(defvar *AutoSaveIncrement* 1)                                                                                                                                                                                        ;Loop counter
(defvar *AutoSaveNumberOfIncrements* 2)                                                                                                                                                                        ;How many backups do you want?
(defvar *AutoSaveBaseLocation* "Directory")                                                                                                                                                        ;Establish autosave location variable

(unless (sd-directory-p (format nil "~AAutosave" (sd-inq-temp-dir)))                                                                                                        ;Check if an autosave directory exists in the user's temp directoy
  (sd-make-directory (format nil "~AAutosave" (sd-inq-temp-dir)))                                                                                                                ;Make Autosave directory
)

(defun AutoSaveBaseline
;  (oli::sd-display-alert (+ (oli::sd-inq-temp-dir) "Autosave/" (oli::get-universal-time)))         
  (setf *AutoSaveBaseLocation* (format nil "~AAutosave/~A" (sd-inq-temp-dir) (get-universal-time)))                                                ;Establish autosave location
  (sd-make-directory *AutoSaveBaseLocation*)                                                                                                                                                        ;Create autosave location
  (sd-display-alert "Beginning Autosave" :icon :info :auto-close-time 5)                                                                                                ;Popup toast warning user what's up
  (sd-with-current-working-directory AutoSaveBaseLocation                                                                                                                                ;Remember CWD, change dir, run these things, revert to CWD
    (save_sd :OVERWRITE :all_at_top :TOP_LEVEL_INSTANCE_FILES :YES :DIRECTORY complete)                                                                        ;Save all items using .sd format
    (sd-display-alert (+ "Autosaved to " *AutoSaveBaseLocation*) :icon :info :auto-close-time 5)                                                ;Popup toast showing location saved to
    (sd-copy-file *AutoSaveBaseLocation* (+ *AutoSaveBaseLocation* "BaseCopy"))                                                                                        ;Capture fallback copy of baseline save
; actually I think I want something like this: (oli:sd-sys-background-job "xcopy C:\\Users\\gregm\\Documents\\AutosaveTest\\20180412a %temp%\\20180412ab\\")
  )
)
 
(defun AutoSaveIncremental
  (oli:sd-display-alert "Beginning Autosave" :icon :info :auto-close-time 1)                                                                                        ;Popup toast warning user what's up
  (sd-with-current-working-directory *AutoSaveBaseLocation*                                                                                                                                ;Remember CWD, change dir, run these things, revert to CWD
    (save_sd_modified :OVERWRITE :all_at_top :TOP_LEVEL_INSTANCE_FILES :YES :DIRECTORY *AutoSaveBaseLocation* complete) ;Save all modified items - super fast
    (oli:sd-display-alert (+ "AutoSave to " *AutoSaveBaseLocation*) :icon :info :auto-close-time 5)                                                ;Popup toast showing location saved to
    (oli:sd-copy-file *AutoSaveBaseLocation* (+ *AutoSaveBaseLocation* "_" AutoSaveIncrement))                                                        ;Capture fallback copy of incremental save
  )       
  (if (= *AutoSaveIncrement* *AutoSaveNumberOfIncrements*)                                                                                                                                ;Loop to capture fallback increments
    (defvar *AutoSaveIncrement* 1)                                                                                                                                                                                ;Reset to 1
        (+ *AutoSaveIncrement* 1)                                                                                                                                                                                        ;Increment by 1
  )       
)

(sd-display-alert "Done loading Autosave" :icon :info :auto-close-time 5)

I'm not sure why I'm getting an error about not being a symbol
Code:

(setf *AutoSaveBaseLocation* (format nil "~AAutosave/~A" (sd-inq-temp-dir) (get-universal-time)))

gmatelich 05-09-2018 10:43 AM

Re: Super Fast Autosave
 
AutoSaveBaseline is looking pretty good
Code:

(defun AutoSaveBaseline ()
  (setf *AutoSaveBaseLocation* (format nil "~AAutosave/~A" (sd-inq-temp-dir) (get-universal-time)))                                                ;Establish autosave location
  (sd-make-directory *AutoSaveBaseLocation*)                                                                                                                                                        ;Create autosave location
  (sd-display-alert "Beginning Autosave" :icon :info :auto-close-time 5)                                                                                                ;Popup toast warning user what's up
  (sd-with-current-working-directory *AutoSaveBaseLocation*                                                                                                                                ;Remember CWD, change dir, run these things, revert to CWD
    (save_sd :OVERWRITE :CWD_CHANGED :SELECT :all_at_top)                                                                                                                                ;Save all items using .sd format
    (sd-sys-background-job (format nil "xcopy ..\\~A ..\\~ABaseCopy /I" (subseq valve::*AutoSaveBaseLocation* (- (length valve::*AutoSaveBaseLocation*) 10)) (subseq valve::*AutoSaveBaseLocation* (- (length valve::*AutoSaveBaseLocation*) 10))))
    (sd-display-alert (format nil "Autosaved to ~A" *AutoSaveBaseLocation*) :icon :info :auto-close-time 5)                                                ;Popup toast showing location saved to
  )
)


gmatelich 05-16-2018 03:34 PM

Re: Super Fast Autosave
 
Code:

#| Just doing a "baseline" save instead of the standard autosave, is a great time saver, since you don't have to wait for the package file to zip (why don't they do that in the background?).
This sequence saves a baseline save using .sd? format to the user's temp directory. Current suggested usage is to turn on Modeling's Autosave function with the 'ask before save' option. When it asks
if you want to save now, say no, then use these tools. The first time per Modeling session you'll need to do AutoSaveBaseline; each baseline creates a copy upon completion to fallback to.
Subsequent saves using AutoSaveIncremental will be substantially quicker; current code cycles through 3 copies of autosaves to fallback to.

For best safety in testing phase, consider doing a new baseline save when heading out to lunch, a meeting, or other opportunity where the delay of the save won't be an irritation. This frequent number of
copies of design space have the potential to quickly fill up your hard drive - OpenAutoSaveDir will take you to the Autosave base directory where you can delete old unneeded directories.

To recover in the case of crash you can go to the most recent autosave directory, sort by file type and load .sd? files, i.e. .sdw, .sdp, .sda, etc. Don't load .sd?c files unless you are only after a
particular instance of part/assy/WP.
|#

(in-package :valve)
(use-package :oli)
(sd-display-alert "Loading Autosave" :icon :info :auto-close-time 5)
(defvar *AutoSaveIncrement* 1)                                                                                                                                                                                        ;Loop counter
(defvar *AutoSaveNumberOfIncrements* 3)                                                                                                                                                                        ;How many backups do you want?
(defvar *AutoSaveBaseLocation* nil)                                                                                                                                                                                ;Establish autosave location variable

(unless (sd-directory-p (format nil "~AAutosave" (sd-inq-temp-dir)))                                                                                                        ;Check if an autosave directory exists in the user's temp directoy
  (sd-make-directory (format nil "~AAutosave" (sd-inq-temp-dir)))                                                                                                                ;Make Autosave directory
)

(defun AutoSaveBaseline ()
  (setf *AutoSaveBaseLocation* (format nil "~AAutosave/~A" (sd-inq-temp-dir) (get-universal-time)))                                                ;Establish autosave location
  (sd-make-directory *AutoSaveBaseLocation*)                                                                                                                                                        ;Create autosave location
  (sd-display-alert "Beginning Baseline Autosave" :icon :info :auto-close-time 5)                                                                                ;Popup toast warning user what's up
  (sd-with-current-working-directory *AutoSaveBaseLocation*                                                                                                                                ;Remember CWD, change dir, run these things, revert to CWD
    (save_sd :OVERWRITE :CWD_CHANGED :SELECT :all_at_top)                                                                                                                                ;Save all items using .sd format
    (sd-sys-background-job (format nil "xcopy ..\\~A ..\\~ABaseCopy /I" (subseq *AutoSaveBaseLocation* (- (length *AutoSaveBaseLocation*) 10)) (subseq *AutoSaveBaseLocation* (- (length *AutoSaveBaseLocation*) 10)))) ;Assumes 10 character timestamp
    (sd-display-alert (format nil "Autosaved to ~A" *AutoSaveBaseLocation*) :icon :info :auto-close-time 5)                                ;Popup toast showing location saved to
  )
)
 
(defun AutoSaveIncremental ()
  (oli:sd-display-alert "Beginning Incremental Autosave" :icon :info :auto-close-time 1)                                                                ;Popup toast warning user what's up
  (sd-with-current-working-directory *AutoSaveBaseLocation*                                                                                                                                ;Remember CWD, change dir, run these things, revert to CWD
    (save_sd_modified :OVERWRITE :all_at_top :TOP_LEVEL_INSTANCE_FILES :YES :DIRECTORY *AutoSaveBaseLocation* complete) ;Save all modified items - super fast
    (sd-display-alert (format nil "Autosaved to ~A" *AutoSaveBaseLocation*) :icon :info :auto-close-time 5)                                ;Popup toast showing location saved to
    (sd-sys-background-job (format nil "xcopy ..\\~A ..\\~A_~A /I" (subseq *AutoSaveBaseLocation* (- (length *AutoSaveBaseLocation*) 10)) (subseq *AutoSaveBaseLocation* (- (length *AutoSaveBaseLocation*) 10)) *AutoSaveIncrement*)) ;Assumes 10 character timestamp
    (sd-display-alert (format nil "Copied incremental to ~A_~A" *AutoSaveBaseLocation* *AutoSaveIncrement*) :icon :info :auto-close-time 5)                                ;Popup toast showing location saved to
  )       
  (if (= *AutoSaveIncrement* *AutoSaveNumberOfIncrements*)                                                                                                                                ;Loop to capture fallback increments
    (setf *AutoSaveIncrement* 1)                                                                                                                                                                                ;Reset to 1
        (setf *AutoSaveIncrement* (+ *AutoSaveIncrement* 1))                                                                                                                                ;Increment by 1
  )       
)

(defun OpenAutoSaveDir ()
  (sd-with-current-working-directory *AutoSaveBaseLocation*                                                                                                                                ;Remember CWD, change dir, run these things, revert to CWD
    (sd-sys-background-job "start ..")
  )
)

(ADD_TOOLBOX_BUTTON :TOOLBOX "TOOLBOX" :LABEL "AutoSave Baseline" :ACTION "(valve::AutoSaveBaseline)")
(ADD_TOOLBOX_BUTTON :TOOLBOX "TOOLBOX" :LABEL "AutoSave Incremental" :ACTION "(valve::AutoSaveIncremental)")
(ADD_TOOLBOX_BUTTON :TOOLBOX "TOOLBOX" :LABEL "Open AutoSave Dir" :ACTION "(valve::OpenAutoSaveDir)")

(sd-display-alert "Done loading Autosave" :icon :info :auto-close-time 5)


Shaba 05-17-2018 10:38 PM

Re: Super Fast Autosave
 
Let me understand..
This Autosave is not automatic?

gmatelich 05-18-2018 08:32 AM

Re: Super Fast Autosave
 
correct, it's not yet automatic. this is really just next step in proof of concept. It still relies on the out of box autosave to use as a timer/counter, but aims to reduce the pain of waiting for autosave to complete.

gmatelich 05-29-2018 09:15 AM

Re: Super Fast Autosave
 
I've moved this code set to GitHub: https://github.com/barebuns/IncrementalAutoSave
I've added Annotation backup to the code as well.
I look forward to anyone's feedback on how this is working for them, and if they've had any unexpected behavior.

tom kirkman 05-29-2018 11:35 AM

Re: Super Fast Autosave
 
Thank you

Once I get through with my current project, I will load it up and try it.

Tom


All times are GMT -8. The time now is 05:13 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.