View Full Version : Request for a Lisp Routine
sorman
2009-08-05, 01:30 AM
I have asked this question before in other forums, but the answers were a bit beyond me.
I am trying to set up a different autosave than what is currently in AutoCAD.
Can a LISP routine be written, that will save a full blown version of the current open drawing. I know that autocad has an autosave with a timer, but that is only handy if you crash autocad. The only time a complete version of the drawing is saved, is with qsave or "cntrl-S".
Like several others, when you get into a drawing, time is the last thought you have.
So, the straight forward question (because I'm still learning AutoLISP and can't do it)
Can a program be written that will keep track of time, and say every 15 minutes, activate qsave?
Could someone provide me and the rest of us, (ie: those of whom might need it), with this routine?
rkmcswain
2009-08-05, 03:06 AM
I've seen versions of what you are asking for all over the internet in various forums.
If none of those will do it..., another alternative would be to write a wrapper for an existing command that you use a lot like ERASE or MOVE. The downside to this is that you may save the drawing when you don't really want to.
(defun C:e ()
(command "._qsave")
(command "._erase")
)
Actually, if you had a timer that saved the current open drawing, you could run into the same problem, saving the drawing when you don't want to. That is why AutoCAD's autosave saves to a DIFFERENT file.
If you are interested in a way to keep the autosave files from being deleted when you close AutoCAD, post back.
Personally, I just press QSAVE every few minutes...
irneb
2009-08-05, 08:21 AM
While agreeing with RK about the QSAVE (Ctrl+S) ... for such an "autosave" lisp I'd advise using the _SAVE command after setting FILEDIA=0. In this case you can save to another filename while still keeping the current file open (it works like a SAVEAS but doesn't change the current DWG to the just saved file). Otherwise using the vlax methods could do a save as well ... probably better if you run this with a timer, since the command line is not used.
As for those disappearing autosaves, Google undelete utilities. They're simply deleted without moving to the recycle bin (as if you pressed Shift+Del in explorer), so an undelete would be able to restore these.
rkmcswain
2009-08-05, 01:48 PM
While agreeing with RK about the QSAVE (Ctrl+S) ... for such an "autosave" lisp I'd advise using the _SAVE command after setting FILEDIA=0. In this case you can save to another filename while still keeping the current file open (it works like a SAVEAS but doesn't change the current DWG to the just saved file).I agree, but I was just addressing the OP's question "Can a program be written that will keep track of time, and say every 15 minutes, activate qsave?" ;) You're exactly right, qsave can be dangerous if it saves something that you didn't want to save...
As for those disappearing autosaves, Google undelete utilities. They're simply deleted without moving to the recycle bin (as if you pressed Shift+Del in explorer), so an undelete would be able to restore these.
What I was thinking of was configuring the directory where the autosave files live, so that they cannot be deleted.
Last paragraph here > http://cadpanacea.com/node/15
irneb
2009-08-05, 02:44 PM
What I was thinking of was configuring the directory where the autosave files live, so that they cannot be deleted.
Last paragraph here > http://cadpanacea.com/node/15Very good idea! However, I'd add the following 2 comments to that:
As stated how an autosave happens, it does not happen as and when the timer fires. The timer is checked at each command issued by the user ... so if you've done some changes and answer the phone (speaking say 30min) the AutoSave at 10min will only happen once you issue a new command.
If your drawings are large, then placing the SAVEFILEPATH to a network share would make for performance loss. Ensure your local HDD is an NTFS system (and not a FAT) ... this would enable you to add the same rights assignments per user to different folders.But as you've stated in Moral of the Story, I'd reiterate: Pressing Crtl+S does not take too much time ... 2 finger operation without moving your hand off the mouse ... come-on it doesn't take any time at all! :lol:
rkmcswain
2009-08-05, 03:26 PM
As stated how an autosave happens, it does not happen as and when the timer fires. The timer is checked at each command issued by the user ... so if you've done some changes and answer the phone (speaking say 30min) the AutoSave at 10min will only happen once you issue a new command.
That is incorrect. Autosave fires whether a command is initiated or not. This can be proven easily in about 90 seconds.
* Open AutoCAD
* Set SAVETIME to 1
* Save the drawing (which resets the timer)
* Draw a line.
* Don't touch the machine for 60+ seconds
Autosave will fire in approximately 60 seconds. It took about 63 seconds here.
If your drawings are large, then placing the SAVEFILEPATH to a network share would make for performance loss.
Yea - I guess I used the wrong term ("server") there. I'll fix that. Thanks.
irneb
2009-08-05, 05:28 PM
That is incorrect. Autosave fires whether a command is initiated or not. This can be proven easily in about 90 seconds.Yes! It works! ;) When was that changed? I can remember in 2005 & 6 we had this problem here ... or am I loosing it? :mrgreen:
ccowgill
2009-08-05, 06:17 PM
I have a routine that I have been using that was written by Peter:
;************************************************************************************
; Automatic Drawing saving program.
; Saves every 10 minutes to the same directory.
; Saves with same name, but adds date and time to filename.
; Written by Peter Jamtgaard copr 2005
;************************************************************************************
I am absolutely positive I got it from the AUGI forums, you could do a search for it, it fires every 10 minutes (configurable) It fires based on a command completed reactor, I have modified it several times to remove commands from the list of commands that will cause it to fire (save, zoom, etc.) If Peter happens to stop by here in this thread and gives me the ok, I will post my revised version.
rkmcswain
2009-08-05, 07:17 PM
Yes! It works! ;) When was that changed? I can remember in 2005 & 6 we had this problem here ... or am I loosing it? :mrgreen:
I don't know - I'm pretty sure I initially tested this on 2006.
I will test on a few older versions and report back what I find...
rkmcswain
2009-08-06, 08:05 PM
I don't know - I'm pretty sure I initially tested this on 2006.
Tested on 2006, works like above.
Tested on R14 - it waits until you initiate a command.
Don't have 2000-2004 right now to test to see when it was fixed.
alanjt
2009-08-07, 05:12 AM
i wrote this a while back for someone in a different forum. it will allow you to specify a time increment, and everytime a command is executed, if the time b/w the last autosave and current time is greater than the specified time, it will issue a qsave.
you are more than welcome to it.
;;; ------------------------------------------------------------------------
;;; AutoSave.lsp v1.0
;;; (Reactor)
;;;
;;; Copyright© 05.24.09
;;; Alan J. Thompson (alanjt)
;;; alanjt@gmail.com
;;;
;;; Permission to use, copy, modify, and distribute this software
;;; for any purpose and without fee is hereby granted, provided
;;; that the above copyright notice appears in all copies and
;;; that both that copyright notice and the limited warranty and
;;; restricted rights notice below appear in all supporting
;;; documentation.
;;;
;;; The following program(s) are provided "as is" and with all faults.
;;; Alan J. Thompson DOES NOT warrant that the operation of the program(s)
;;; will be uninterrupted and/or error free.
;;;
;;; Allows user to specify a number of minutes for an autosave time and
;;; everytime a command is executed, if the duration between time from the
;;; last time the drawing was saved (with AutoSave) is greater or equal to
;;; the designated AutoSave minutes, the drawing will be saved.
;;; Everything works transparently.
;;;
;;; Revision History:
;;;
;;; ------------------------------------------------------------------------
(vl-load-com)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;; REACTORS & SUBROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (not *CommandReactors-AutoSave*)
(setq *CommandReactors-AutoSave*
(vlr-command-reactor
nil
'((:vlr-commandWillStart . StrtCMD-AutoSave)
)
) ;_ vlr-command-reactor
) ;_ setq
) ;_ if
(defun StrtCMD-AutoSave
(calling-reactor StrtCMD-AutoSaveInfo / theCMDStrt)
(setq theCMDStrt (strcase (nth 0 StrtCMD-AutoSaveInfo) t))
(cond
((and AS:TimeAmount
AS:Timer
(>= (- (/ (* 86400 (getvar "tdusrtimer")) 60) AS:Timer)
AS:TimeAmount
) ;_ >
) ;_ and
(vla-save
(vla-get-activedocument
(vlax-get-acad-object)
) ;_ vla-get-activedocument
) ;_ vla-save
(setq AS:Timer (/ (* 86400 (getvar "tdusrtimer")) 60))
(princ "\nDrawing has been saved with AutoSave.\n")
)
) ;cond
) ;_ defun
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAIN ROUTINE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:AutoSave (/)
(and (setq AS:TimeAmount
(getint "\nNumber of minutes between autosaves: ")
) ;_ setq
(setq AS:Timer (/ (* 86400 (getvar "tdusrtimer")) 60))
(prompt (strcat "\nAutosave timer set to: "
(itoa AS:TimeAmount)
" minutes."
) ;_ strcat
) ;_ prompt
) ;_ and
(princ)
) ;_ defun
(prompt
"\nAutoSave loaded, type 'AutoSave' to set AutoSave time."
) ;_ prompt
(princ)
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.