Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Autosave I need it to be a TRUE AUTOMATIC SAVE BACKUP DWG

5 REPLIES 5
Reply
Message 1 of 6
crt-fresno
4026 Views, 5 Replies

Autosave I need it to be a TRUE AUTOMATIC SAVE BACKUP DWG

I need something that Does what AUTOSAVE used to to (accidentally). Truly save a dwg as a backup (or other extension) at a set time interval...He likes every 3-5 minutes.

 

The person this is for, has used ACAD since before ACAD14 and USED the AUTOSAVE as most of his saving..Trying to get the REMEMBER TO SAVE OFTEN - Is NOT working!!!

 

He has TONS of Interruptions (calls, conference calls, e-mails, needing to get info from the Web) always happening and can easily have ACAD sitting for Hours before he can get back to it...

 

I don't understand how to write a LISP of Reactor routine. So if someone could get/find one for me with either a Set Timer or Qty of Commands. That would be Great.

 

I have printed out LOTS of the AUTOSAVE POSTS and am Still lost. Some say LISP is better, others say REACTOR. At one time I was given a LISP Command and used APPLOAD to get it into my ACAD and put it in the ''When you Begin ACAD put this in also'' spot. Not sure if that is still around and ACAD finally put what I wanted as a Command.

 

He runs Windows 7 and ACAD 2011 (Acad 14 commands mostly - and a few more recent ones)

 

I think he would like a DUEL BACKUP option also. (ei; .bak1 and .bak2 (the older one) or .sav1 and .sav2) and these Backups put back into the folder where the Dwg is. Like the .bak does now.

5 REPLIES 5
Message 2 of 6
Lee_Mac
in reply to: crt-fresno

Timers are a pain to implement using reactors since the reactor would need to monitor the system clock at regular intervals, for example by monitoring a callback event which is likely to occur regularly.

 

To suggest an alternative, the following simple reactor-based code will save the current drawing after every 20 commands:

 

(vl-load-com)
(if (null *autosave-reactor*)
    (setq *autosave-reactor*
        (vlr-command-reactor "autosave"
           '(
                (:vlr-commandended     . autosave)
                (:vlr-commandcancelled . autosave)
                (:vlr-commandfailed    . autosave)
            )
        )
    )
)
(setq *autosave-acdoc* (vla-get-activedocument (vlax-get-acad-object))
      *autosave-count* 0
)
(defun autosave ( obj arg )
    (if (and (zerop (rem (setq *autosave-count* (1+ *autosave-count*)) 20))
             (= 1 (getvar 'dwgtitled))
        )
        (vla-save *autosave-acdoc*)
    )
    (princ)
)
(princ)

If you don't have experience with reactor-based programs, there is no 'command' to run the program, simply load the program and the Visual LISP Command Reactor will run in the background, monitoring for when a command has ended, is cancelled by the user, or has failed.

 

After every 20 commands (this number can of course be changed to suit your preferences) the reactor callback function will save the active drawing.

 

This is of course only a very simple draft of such a utility, the program could be enhanced to save a copy of the drawing to a different directory, or the same directory etc.

 

I hope this helps!

Message 3 of 6
crt-fresno
in reply to: Lee_Mac

Great...

Now the Silly questions....


1) How do I take what you sent on the E-mail and put it WHERE for the ACAD to use (Assumed a Cut and Paste). But into What named item located Where (Assumed under my ACAD Support Folder).

2) If NOT pasted into another spot, Then what is its NAME (Assumed AUTOSAVE-REACTOR)

3) I assume that I Load it through the Appload from within ACAD and Path to where it is. Assumed after that it is Automatic from then on every time My Person opens ACAD.

Crt-fresno
Message 4 of 6
Lee_Mac
in reply to: crt-fresno

In answer to your questions, follow these steps carefully:

 

  1. Open Notepad to a new file (or another plain text editor).

     

  2. Copy the posted code into Notepad.

     

  3. Save the file under any filename but with a .lsp extension, e.g. 'autosave.lsp' (Important: Ensure 'Save as Type' is set to 'All Files').

     

  4. Save or copy this new LISP file to any AutoCAD Support File Search Path (these paths are listed under the 'Files' tab of the 'Options' dialog).

     

  5. Open AutoCAD to a new blank drawing.

     

  6. At the AutoCAD command-line, type:

     

    (findfile "acaddoc.lsp")

     

  7. If the above returns a filepath, navigate to this filepath in Windows Explorer, open the existing acaddoc.lsp file and add the following on new lines at the end of the existing file.

     

  8. If the above returns nil, open Notepad again to a new file.

     

  9. In the new/existing file, type:

     

    (load "autosave.lsp" "Unable to load Autosave program.")
    (princ)
    Where autosave.lsp is the name of the LISP file saved earlier.

     

  10. If working with the existing acaddoc.lsp file, save the modifications to the file.

     

  11. If working in a new Notepad file, save the file as 'acaddoc.lsp' (again, ensure 'Save as Type' is set to 'All Files') to an AutoCAD Support File Search Path (can be the same location as the 'autosave.lsp' for convenience).

     

  12. Restart AutoCAD.

     

When a drawing is opened (new or existing), AutoCAD will automatically search the working directory & all support file search paths (in the order listed in the 'Files' tab) for a file called 'acaddoc.lsp'; AutoCAD will then automatically load the first such file found into the current drawing session, hence evaluating all AutoLISP expressions contained in the file.

 

Of course, you could alternatively copy the reactor code directly into the acaddoc.lsp file, however, in my opinion it is more manageable to have each AutoLISP program as a separate file loaded from the acaddoc.lsp, as the files can easily be replaced should the program be updated at a later date.

 

Using the acaddoc.lsp in lieu of the Startup Suite (within the AppLoad command) also makes migration to other machines a breeze, since the acaddoc.lsp and any accompanying AutoLISP programs can simply be copied to a support file search path (SFSP) on the new machine, and the programs will automatically be loaded with no further configuration required.

 

Alternatively, if you want to ensure a program is available for all users on a network, rather than using the Startup Suite you can add a common network path accessible by all users as a SFSP on every user's system and save the acaddoc.lsp and any accompanying programs to this network path.

 

This way, you (as a CAD Manager perhaps) have complete control over which programs are loaded on your users' machines, and, should any program need to be updated in the future, you can modify the single file at the network location and the change will be reflected across all computers referencing the network path as a SFSP.

 

Of course, 'with power comes responsibility' since the inherent behaviour of the acaddoc.lsp opens the door should anyone choose to insert malicious code into this file. These dangers are described in my post on the 'Dangers of the acaddoc.lsp'.

 

I hope the above explanations are clear, if not just ask.

 

Lee

Message 5 of 6
rkmcswain
in reply to: crt-fresno

Or you could just ensure that SAVETIME=1 (or whatever interval), and ensure that the folder for the autosave files has WRITE access, but not DELETE access.
R.K. McSwain     | CADpanacea | on twitter
Message 6 of 6
ActivistInvestor
in reply to: Lee_Mac


@Lee_Mac wrote:

Timers are a pain to implement using reactors since the reactor would need to monitor the system clock at regular intervals, for example by monitoring a callback event which is likely to occur regularly.

 

To suggest an alternative, the following simple reactor-based code will save the current drawing after every 20 commands:

 

After every 20 commands (this number can of course be changed to suit your preferences) the reactor callback function will save the active drawing.

 

This is of course only a very simple draft of such a utility, the program could be enhanced to save a copy of the drawing to a different directory, or the same directory etc.

 

I hope this helps!


Command reactors fire when commands are started/ended by scripting (e.g., LISP's (command) function or its ObjectARX equivalent acedCommand(), etc.).

 

You can probably find thousands of LISP scripts in this discussion group's history that execute one or more AutoCAD commands repeatedly in a loop of some sort, hundreds or even thousands of times in the matter of a few seconds.

 

Perhaps you might want to re-think your proposed solution?

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost