; =========================================================
; AUTOSAVE.LSP By: Jeff Pilcher
;
; This is an AutoLISP routine for use with the
; AutoCAD drafting software.
;
; I am providing this routine to other users of
; AutoCAD under the SHAREWARE concept. I would
; like to recover some of the cost of my time
; spent developing this and other AutoLISP
; routines for AutoCAD, by asking for voluntary
; payments.
;
; If you find this routine is useful to you in
; doing paying work, please send $5 to:
;
; Jeffrey S. Pilcher
;
; Production Systems
; P.O. Box 218
; Richmond, IL 60071
;
; (815) 678-4562
;
; Obviously $5 is not going to make me rich, or break
; your bank account. It will however, show me that
; someone out there appreciates my efforts, and give
; me the incentive to write more useful routines.
;
; I would be very interested in seeing any routines
; written by you or anyone else. In other words, an
; exchange of routines would make me as happy as a
; $5 payment, (well, almost as happy).
;
; Feel free to pass this routine on to other AutoCAD
; users, but PLEASE, do not remove these comments.
;
; Good luck, have fun, and LONG LIVE AutoDESK !!!
;
; =========================================================
;
;
; This is a routine to automatically save your drawing at
; regular intervals during the editing session.
;
; There are a lot of autosave routines out there, but I think
; this is the most straight forward of the bunch.
;
; AUTOSAVE.LSP main features:
;
; 1) Can be turned on or off as you see fit.
;
; 2) You specify how often you want to AUTOSAVE.
;
; 3) When it is not time to AUTOSAVE, it tells
; you how much time is left so you know exactly
; what is happenning.
;
; 4) When it is AUTOSAVING, it tells you the name
; of the drawing being AUTOSAVED.
;
; INSTALLATION:
;
; To utilize this routine you should include the code portion
; in your ACAD.LSP file.
;
; After you have installed AUTOSAVE.LSP in your ACAD.LSP file
; you will need to include the command "(c:setauto)" as the
; last statement in your ACAD.LSP file. This will cause
; AutoCAD to prompt the user with the message:
;
; Do you want to do AUTOSAVES ?
;
; upon entering the drawing editor.
;
; Then include the command AUTOSAVE under many of the menu
; picks in your tablet menu.
;
;
; OPERATION:
;
; When you enter the drawing editor, and as the ACAD.LSP
; file is being loaded, the operator will be asked if he/she
; would like to do AUTOSAVES:
;
; Do you want to do AUTOSAVES ?
;
; A response of [ y ] or [ Y ] will turn AUTOSAVE on, AutoCAD
; will tell the operator that AUTOSAVE is on with the prompt:
;
; AUTOSAVE is on.
;
; Any other response will turn AUTOSAVE off, AutoCAD will
; tell the operator that AUTOSAVE is off with the prompt:
;
; AUTOSAVE is off.
;
; If the operator has chosen to do AUTOSAVES by responding
; [ y ] or [ Y ] he/she will be asked how often to AUTOSAVE
; with the prompt:
;
; How often would you like to AUTOSAVE, in minutes <15>:
;
; The operator should at this time enter a number indicating
; how often they would like AutoCAD to AUTOSAVE thier drawing.
; The default is 15 minutes. If 15 minutes is acceptable,
; simply hit <ENTER>.
;
; Upon picking one of the tablet picks which contains the
; AUTOSAVE command, AutoCAD will check to see how long it has
; been since it last AUTOSAVED your drawing. If the time
; since the last AUTOSAVE has exceeded the desired interval,
; AutoCAD will automatically save your drawing for you, and
; tell you what is happenning with the prompt:
;
; AUTOSAVING: <dwgname>
; Please stand by ....
;
; (never again will you loose 4 hours of work due to a systems
; crash or power failure).
;
; If the time since the last AUTOSAVE has not exceeded the
; desired interval, AutoCAD will tell you with the prompt:
;
; Not time yet .... xx.x minutes left.
;
; As you can see, it will tell how much time is left until the
; next AUTOSAVE.
;
;
; EXTRA FEATURES:
;
; The AUTOSAVE routine can be turned on or off at any time you
; desire while in the drawing editor by typing [ SETAUTO ], at
; the command prompt, and answering the prompt:
;
; Do you want to do AUTOSAVES ?
;
; with the proper response. This prompt is the same prompt you
; get when you first enter the drawing editor. Therefore you
; will also be asked to enter a time interval for the AUTOSAVE
; program. So not only can you turn AUTOSAVVES on or off, but,
; you can also change the time interval whenever you like.
;
;
(defun setauto ()
(setq answer (strcase (getstring "\nDo you want to do AUTOSAVES ? ")))
(if (> (strlen answer) 1)
(setq answer (substr answer 1 1))
)
(if (= answer "Y")
(progn
(prompt "\nAUTOSAVE is on.")
(print)
(setq minutes (getreal "\nHow often would you like to AUTOSAVE, in minutes <15>: "))
(if (= minutes nil)
(setq minutes 15.0)
)
)
(prompt "\nAUTOSAVE is off.")
)
(print)
)
(defun C:autosave ()
(if (= answer "Y")
(saveit)
(prompt "\nAUTOSAVE is turned off !")
)
(print)
)
(defun saveit ()
(if (= D1 nil)
(setq D1 (getvar "DATE"))
)
(if (> (* (- (getvar "DATE") D1) 1440.0) minutes)
(progn
(setvar "cmdecho" 0)
(prompt (strcat "\nAUTOSAVING: " (getvar "dwgname")))
(prompt "\nPlease stand by .... ")
(print)
(command "SAVE" "")
(prompt "\nAUTOSAVE complete.")
(prompt "\nThank you for waiting.")
(setq D1 (getvar "DATE"))
(setvar "cmdecho" 1)
)
(progn
(prompt "\nNot time yet .... ")
(princ (rtos (- minutes (* (- (getvar "DATE") D1) 1440.0)) 2 1))
(princ " minutes left.")
)
)
(print)
)
;
(setauto)
Sounds interesting Jeff, would you post it?
Thanks,
Ron
Option Explicit
Dim command_count As Long
Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
'***Below code is to AUTO save the drawing every 25 commands,
If ThisDrawing.GetVariable("DWGTITLED") = 1 Then 'don't use on new, unsaved drawings
Select Case CommandName
Case UCase("undo"), UCase("u"), Ucase("zoom"), Ucase("z"), Ucase("pan")
command_count = command_count
Case Else
command_count = command_count + 1
If command_count = 25 Then 'change this to any number you want
ThisDrawing.Save
command_count = 0
End If
End Select
End If
End Sub
Does autosave do a full save to dwg format?You're correct, AUTOSAVE is for catostrophic failures only and should never be used instead of proper saving standards and procedures. We "beat" into our users to save early save often and have set CTRL+S to run a qsave, and have qsave built into a couple of the more common buttons.
I was always under the impression that autosave was an emergency only option, and should only be re-named and used in the direst of circumstances.
We "beat" into our users to save early save often and have set CTRL+S to run a qsave.
Hangin' in, typing's a bit... pain.. one finger each hand, aim and punch. I'm hoping the exercise wakes up something.Quote from: CADaverWe "beat" into our users to save early save often and have set CTRL+S to run a qsave.
Indeed. (http://www.theswamp.org/phpBB2/viewtopic.php?p=54108#54108)
Good to see you posting Randy, hope you're doing well my friend.
Jeff's save by number of commands works great.
Option Explicit
Dim command_count As Long
Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
'***Below code is to AUTO save the drawing every 15 commands,
If ThisDrawing.GetVariable("DWGTITLED") = 1 Then 'don't use on new, unsaved drawings
Select Case CommandName
Case UCase("undo"), UCase("u"), UCase("zoom"), UCase("z"), UCase("pan")
command_count = command_count
Case UCase("QSAVE"), UCase("SAVE")
command_count = 0
Case Else
command_count = command_count + 1
If command_count = 15 Then 'change this to any number you want
ThisDrawing.Save
command_count = 0
End If
End Select
End If
End Sub
Option Explicit
Dim command_count As Long
Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
'***Below code is to AUTO save the drawing every 25 commands,
If ThisDrawing.GetVariable("DWGTITLED") = 1 And ThisDrawing.ReadOnly = False Then 'don't use on new, unsaved drawings or readonly
Select Case CommandName
Case UCase("UNDO"), UCase("U"), UCase("ZOOM"), UCase("Z"), UCase("PAN")
command_count = command_count
Case UCase("QSAVE"), UCase("SAVE")
command_count = 0
Case Else
command_count = command_count + 1
If command_count = 25 Then 'change this to any number you want
ThisDrawing.Save
command_count = 0
End If
End Select
End If
End Sub
(defun copy_backup_as (/ *error* activedoc docfullname backuppath archivename)
;; IAcadDocument Object
(setq activedoc (vla-get-activedocument (vlax-get-acad-object)))
;;
;;------ Set Error Trap --------------------------
;;
(defun *error* (msg /) (kb:on-error msg))
(vla-endundomark activedoc) ; end any open undo group
(vla-startundomark activedoc) ; start new group
;;
;;----- Main --------------------------
;;
(vla-save activedoc)
(if (and (not (= 0 (strlen (setq docfullname (vla-get-fullname activedoc)))))
(setq backuppath (dos_mkdir (strcat (vl-filename-directory docfullname)
"\\DRAWINGArchive"
)
)
)
(setq archivename (strcat backuppath
(vl-filename-base (vla-get-name activedoc))
"-"
(rtos (* (getvar "cdate") 1000000) 2 0)
".dwg"
)
)
)
(vl-file-copy docfullname archivename)
(alert "Ooooops. Unable to establish ArchiveName.")
)
(prompt (strcat "\n Archived file : " archivename))
(*error* nil)
(princ)
)
Does autosave do a full save to dwg format?Yes it does. The only difference between a dwg and an sv$ is the extension. There is nothing unsafe or scary about using an autosave. That being said, if you still want a time interval based save, you can set your savetime to the time between saves and use this.
I was always under the impression that autosave was an emergency only option, and should only be re-named and used in the direst of circumstances.
Private Sub AcadDocument_EndSave(ByVal FileName As String)
If Right(FileName, 3) = "sv$" Then
ThisDrawing.Save
End If
End Sub
Private Sub AcadDocument_EndSave(ByVal FileName As String)
If Right(FileName, 3) = "sv$" Then
If ThisDrawing.ReadOnly = False Then
ThisDrawing.Save
End If
End If
End Sub
;_____________________________________________________________________________
;;MAKES COPY OF DRAWING IN C:\AutoCAD-BAK
;_____________________________________________________________________________
(defun copydwg (/ destdir dwgdir *date* hour)
(if (not (wcmatch (getvar 'DWGNAME) "Drawing*.dwg"))
(progn
(defun *date* (/ curdate curtime)
(setq curdate (rtos (fix (getvar 'cdate)) 2 0)
curtime (strcat (substr curdate 5 2) "-" (substr curdate 7 2) "-" (substr curdate 1 4)))
)
(defun hour (/ ctime ampm stime)
(setq ctime (rtos (rem (getvar 'cdate) 1) 2 6)
ampm (if (<= (atof (substr ctime 3 2)) 12) "AM" "PM")
stime (strcat (substr ctime 3 2)))
)
;Makes C:\AutoCAD-BAK\currentdate\hour if it doesn't already exist
(if (not
(vl-file-directory-p (strcat "C:/AutoCAD-BAK/")))
(vl-mkdir (strcat "C:/AutoCAD-BAK/"))
)
(if (not
(vl-file-directory-p (strcat "C:/AutoCAD-BAK/" (*date*))))
(vl-mkdir (strcat "C:/AutoCAD-BAK/" (*date*)))
)
(if (not
(vl-file-directory-p (strcat "C:/AutoCAD-BAK/" (*date*) "/" (hour))))
(vl-mkdir (strcat "C:/AutoCAD-BAK/" (*date*) "/" (hour)))
)
;For some reason the files get huge if not deleted then saved on top of
(if (findfile (strcat "C:/AutoCAD-BAK/" (*date*) "/" (hour) "/" (getvar 'dwgname)))
(vl-file-delete (strcat "C:/AutoCAD-BAK/" (*date*) "/" (hour) "/" (getvar 'dwgname)))
)
(setq destdir (strcat "C:/AutoCAD-BAK/" (*date*) "/" (hour) "/" (getvar 'dwgname))
dwgdir (strcat (getvar 'dwgprefix) (getvar 'dwgname))
)
(vl-file-copy dwgdir destdir T)
)
)
)
(copydwg)
;_____________________________________________________________________________
;;COMMAND REACTORS
;_____________________________________________________________________________
(vlr-command-reactor nil '((:vlr-commandEnded . endCommand)))
(defun endCommand (calling-reactor endcommandInfo / thecommandend)
(setq thecommandend (nth 0 endcommandInfo))
(cond
((= thecommandend "QSAVE") (copydwg))
((= thecommandend "SAVE") (copydwg))
)
)
Here is a lisp to autosave your drawings, this does an actual save.
Be aware it will save over your drawings so if you don't want to save changes you need to undo everything prior to closing a drawing.
I stopped using it after I overwrote an architects drawings and had to beg him for another copy.Code: [Select]; =========================================================
; AUTOSAVE.LSP By: Jeff Pilcher
;
; This is an AutoLISP routine for use with the
; AutoCAD drafting software.
;
; I am providing this routine to other users of
; AutoCAD under the SHAREWARE concept. I would
; like to recover some of the cost of my time
; spent developing this and other AutoLISP
; routines for AutoCAD, by asking for voluntary
; payments.
;
; If you find this routine is useful to you in
; doing paying work, please send $5 to:
;
; Jeffrey S. Pilcher
;
; Production Systems
; P.O. Box 218
; Richmond, IL 60071
;
; (815) 678-4562
;
; Obviously $5 is not going to make me rich, or break
; your bank account. It will however, show me that
; someone out there appreciates my efforts, and give
; me the incentive to write more useful routines.
;
; I would be very interested in seeing any routines
; written by you or anyone else. In other words, an
; exchange of routines would make me as happy as a
; $5 payment, (well, almost as happy).
;
; Feel free to pass this routine on to other AutoCAD
; users, but PLEASE, do not remove these comments.
;
; Good luck, have fun, and LONG LIVE AutoDESK !!!
;
; =========================================================
;
;
; This is a routine to automatically save your drawing at
; regular intervals during the editing session.
;
; There are a lot of autosave routines out there, but I think
; this is the most straight forward of the bunch.
;
; AUTOSAVE.LSP main features:
;
; 1) Can be turned on or off as you see fit.
;
; 2) You specify how often you want to AUTOSAVE.
;
; 3) When it is not time to AUTOSAVE, it tells
; you how much time is left so you know exactly
; what is happenning.
;
; 4) When it is AUTOSAVING, it tells you the name
; of the drawing being AUTOSAVED.
;
; INSTALLATION:
;
; To utilize this routine you should include the code portion
; in your ACAD.LSP file.
;
; After you have installed AUTOSAVE.LSP in your ACAD.LSP file
; you will need to include the command "(c:setauto)" as the
; last statement in your ACAD.LSP file. This will cause
; AutoCAD to prompt the user with the message:
;
; Do you want to do AUTOSAVES ?
;
; upon entering the drawing editor.
;
; Then include the command AUTOSAVE under many of the menu
; picks in your tablet menu.
;
;
; OPERATION:
;
; When you enter the drawing editor, and as the ACAD.LSP
; file is being loaded, the operator will be asked if he/she
; would like to do AUTOSAVES:
;
; Do you want to do AUTOSAVES ?
;
; A response of [ y ] or [ Y ] will turn AUTOSAVE on, AutoCAD
; will tell the operator that AUTOSAVE is on with the prompt:
;
; AUTOSAVE is on.
;
; Any other response will turn AUTOSAVE off, AutoCAD will
; tell the operator that AUTOSAVE is off with the prompt:
;
; AUTOSAVE is off.
;
; If the operator has chosen to do AUTOSAVES by responding
; [ y ] or [ Y ] he/she will be asked how often to AUTOSAVE
; with the prompt:
;
; How often would you like to AUTOSAVE, in minutes <15>:
;
; The operator should at this time enter a number indicating
; how often they would like AutoCAD to AUTOSAVE thier drawing.
; The default is 15 minutes. If 15 minutes is acceptable,
; simply hit <ENTER>.
;
; Upon picking one of the tablet picks which contains the
; AUTOSAVE command, AutoCAD will check to see how long it has
; been since it last AUTOSAVED your drawing. If the time
; since the last AUTOSAVE has exceeded the desired interval,
; AutoCAD will automatically save your drawing for you, and
; tell you what is happenning with the prompt:
;
; AUTOSAVING: <dwgname>
; Please stand by ....
;
; (never again will you loose 4 hours of work due to a systems
; crash or power failure).
;
; If the time since the last AUTOSAVE has not exceeded the
; desired interval, AutoCAD will tell you with the prompt:
;
; Not time yet .... xx.x minutes left.
;
; As you can see, it will tell how much time is left until the
; next AUTOSAVE.
;
;
; EXTRA FEATURES:
;
; The AUTOSAVE routine can be turned on or off at any time you
; desire while in the drawing editor by typing [ SETAUTO ], at
; the command prompt, and answering the prompt:
;
; Do you want to do AUTOSAVES ?
;
; with the proper response. This prompt is the same prompt you
; get when you first enter the drawing editor. Therefore you
; will also be asked to enter a time interval for the AUTOSAVE
; program. So not only can you turn AUTOSAVVES on or off, but,
; you can also change the time interval whenever you like.
;
;
(defun setauto ()
(setq answer (strcase (getstring "\nDo you want to do AUTOSAVES ? ")))
(if (> (strlen answer) 1)
(setq answer (substr answer 1 1))
)
(if (= answer "Y")
(progn
(prompt "\nAUTOSAVE is on.")
(print)
(setq minutes (getreal "\nHow often would you like to AUTOSAVE, in minutes <15>: "))
(if (= minutes nil)
(setq minutes 15.0)
)
)
(prompt "\nAUTOSAVE is off.")
)
(print)
)
(defun C:autosave ()
(if (= answer "Y")
(saveit)
(prompt "\nAUTOSAVE is turned off !")
)
(print)
)
(defun saveit ()
(if (= D1 nil)
(setq D1 (getvar "DATE"))
)
(if (> (* (- (getvar "DATE") D1) 1440.0) minutes)
(progn
(setvar "cmdecho" 0)
(prompt (strcat "\nAUTOSAVING: " (getvar "dwgname")))
(prompt "\nPlease stand by .... ")
(print)
(command "SAVE" "")
(prompt "\nAUTOSAVE complete.")
(prompt "\nThank you for waiting.")
(setq D1 (getvar "DATE"))
(setvar "cmdecho" 1)
)
(progn
(prompt "\nNot time yet .... ")
(princ (rtos (- minutes (* (- (getvar "DATE") D1) 1440.0)) 2 1))
(princ " minutes left.")
)
)
(print)
)
;
(setauto)
Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
On Error GoTo Err_Trapper
'***Below code is to AUTO save the drawing every 20 commands,
Select Case CommandName
Case UCase("UNDO"), UCase("U"), UCase("ZOOM"), UCase("Z"), UCase("PAN")
command_count = command_count
Case UCase("QSAVE"), UCase("SAVE")
command_count = 0
Case Else
command_count = command_count + 1
If command_count > 20 Then 'change this to any number you want
Dim strFN As String
strFN = "H:\backup\AutoSaves\" & ThisDrawing.GetVariable("LOGINNAME") & "-" & ThisDrawing.Name
ThisDrawing.SaveAs strFN
command_count = 0
End If
End Select
Exit Sub
Err_Trapper:
Err.Clear
Exit Sub
End Sub
Option Explicit
Dim command_count As Long
Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
On Error GoTo Err_Trapper
'***Below code is to AUTO save the drawing every 20 commands,
Select Case CommandName
Case UCase("UNDO"), UCase("U"), UCase("ZOOM"), UCase("Z"), UCase("PAN")
command_count = command_count
Case UCase("QSAVE"), UCase("SAVE")
command_count = 0
Case Else
command_count = command_count + 1
If command_count > 20 Then 'change this to any number you want
Dim strFN As String
Dim sset As AcadSelectionSet
Set sset = vbdPowerSet("testSS")
strFN = "H:\backup\AutoSaves\" & ThisDrawing.GetVariable("LOGINNAME") & "-" & ThisDrawing.Name
ThisDrawing.Export strFN, "DXF", sset
command_count = 0
End If
End Select
Exit Sub
Err_Trapper:
Err.Clear
Exit Sub
End Sub
Public Function vbdPowerSet(strName As String) As AcadSelectionSet
'''Use this to create a selection set that way it will never be doubled
Dim objSelSet As AcadSelectionSet
Dim objSelCol As AcadSelectionSets
Set objSelCol = ThisDrawing.SelectionSets
For Each objSelSet In objSelCol
If objSelSet.Name = strName Then
objSelCol.Item(strName).Delete
Exit For
End If
Next
Set objSelSet = objSelCol.Add(strName)
Set vbdPowerSet = objSelSet
End Function
QuoteDoes autosave do a full save to dwg format?Yes it does. The only difference between a dwg and an sv$ is the extension. There is nothing unsafe or scary about using an autosave.
I was always under the impression that autosave was an emergency only option, and should only be re-named and used in the direst of circumstances.
I am looking for advice.
I am hoping to be able to write a lisp which performs a qsave every 5 or 10 minutes. Can anyone give me any ideas on where to start, and if there is a function in lisp that calculates time.
Be prepared for "dumb" questions, as I am trying to write my first proper lisp command. :?
Many thanks an advance