Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Contributor
crt-fresno
Posts: 30
Registered: ‎06-16-2003
Message 1 of 4 (753 Views)

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

753 Views, 3 Replies
08-14-2013 02:30 PM

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.

*Expert Elite*
Lee_Mac
Posts: 1,109
Registered: ‎12-29-2009
Message 2 of 4 (740 Views)

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

08-14-2013 04:00 PM 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!

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Active Contributor
crt-fresno
Posts: 30
Registered: ‎06-16-2003
Message 3 of 4 (686 Views)

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

08-15-2013 09:21 AM 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
*Expert Elite*
Lee_Mac
Posts: 1,109
Registered: ‎12-29-2009
Message 4 of 4 (675 Views)

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

08-15-2013 09:52 AM 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

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community