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

Purge on Exit

14 REPLIES 14
Reply
Message 1 of 15
alan1959
760 Views, 14 Replies

Purge on Exit

I am trying to "purge on exit" when I close a drawing. I have changed the SAVE commands within the CUI to accomplish a purge on save as well as changed the CLOSE commands in the CUI.

 

What I want to do is modify the red X close option for the actual windowor program close X in the top right corner of the screen. Any help on how I can do this would be appreciated. Thanks.

14 REPLIES 14
Message 2 of 15
Lee_Mac
in reply to: alan1959

Use an Editor Reactor, triggered upon the BeginClose Event to evaluate a callback function which calls the PurgeAll method of the Document Object. The only downside is that the PurgeAll method will not purge Multileader Styles, but you will not be able to use a call to the command version from a reactor callback function.

 

Something along the lines of:

 

(if (null *editor-reactor*)
    (setq *editor-reactor* (vlr-editor-reactor nil '((:vlr-beginclose . purgedwg))))
)
(defun purgedwg ( reactor params )
    (if (null *acdoc*)
        (setq *acdoc* (vla-get-activedocument (vlax-get-acad-object)))
    )
    (if (= 1 (getvar 'DWGTITLED))
        (progn
            (repeat 3 (vla-purgeall *acdoc*))
            (vla-save *acdoc*)
        )
    )
    (princ)
)
(vl-load-com)

 

Message 3 of 15
alan1959
in reply to: alan1959

how do I load this or where do I insert this to make it run automatically?

Message 4 of 15
Lee_Mac
in reply to: alan1959

As you can see there is no command syntax for the program since the reactor will fire automatically, you just need to ensure the code is loaded into the drawing.

 

The code can be loaded in the same way as you would with any other LISP program, using either the ACADDOC.lsp (recommended) or Startup Suite in the AppLoad dialog.

 

My tutorial here may help you in this respect.

 

Lee

Message 5 of 15
Patchy
in reply to: Lee_Mac

Hi Lee

 

Why it didn't work until I moved the line (vl-load-com) at the bottom to the top of the code and it worked perfectly?

 

Patchy

Message 6 of 15
Lee_Mac
in reply to: Patchy


Patchy wrote:

Hi Lee

 

Why it didn't work until I moved the line (vl-load-com) at the bottom to the top of the code and it worked perfectly?


Oops! Sorry, yes (vl-load-com) should be at the top.

 

The reactor is initialised at the top, this requires Visual LISP.

Message 7 of 15
alan1959
in reply to: alan1959

Okay this worked like a charm. Now to throw a wrench in the works.... it there a way to have the purge not function if when exiting you want to click on the NO option for saving changes when exiting? As it works now it purges no matter what and saves the drawing even if you click NO to saving changes.

Message 8 of 15
Lee_Mac
in reply to: alan1959


alan1959 wrote:

Okay this worked like a charm. Now to throw a wrench in the works.... it there a way to have the purge not function if when exiting you want to click on the NO option for saving changes when exiting? As it works now it purges no matter what and saves the drawing even if you click NO to saving changes.


Try this:

 

(vl-load-com)
(if (null *editor-reactor*)
    (setq *editor-reactor* (vlr-editor-reactor nil '((:vlr-beginclose . purgedwg))))
)
(defun purgedwg ( reactor params )
    (if (null *acdoc*)
        (setq *acdoc* (vla-get-activedocument (vlax-get-acad-object)))
    )
    (if
        (and
            (= 1 (getvar 'DWGTITLED))
            (= 0 (getvar 'DBMOD))
        )
        (progn
            (repeat 3 (vla-purgeall *acdoc*))
            (vla-save *acdoc*)
        )
    )
    (princ)
)
(princ)

 

Message 9 of 15
alanjt_
in reply to: Lee_Mac

What if certain changes are made within the startup (layers, styles, etc. inserted)? The dbmod variable will be something other than 0.

Wouldn't it just be safer to add a purge call to the startup and/or have a custom close+purge+save command?

 

Also, while it is minor, know that vla-purgeall will not include MLeader styles.

Message 10 of 15
Lee_Mac
in reply to: alanjt_


alanjt_ wrote:

What if certain changes are made within the startup (layers, styles, etc. inserted)? The dbmod variable will be something other than 0.


 

 Yes, but this would have no effect on the correct evaluation of the callback function, since, if the DBMOD variable is something other than zero when the user closes the drawing, the 'Save Changes' prompt will appear - If the user decides not to save changes, the DBMOD remains non-zero and the drawing is not purged. If the user decides to save changes, the DBMOD is reset to zero and the drawing is purged as expected.

 


alanjt_ wrote:

Also, while it is minor, know that vla-purgeall will not include MLeader styles.



Lee_Mac wrote:

The only downside is that the PurgeAll method will not purge Multileader Styles...


 

Message 11 of 15
alanjt_
in reply to: Lee_Mac

So, what happens if the user is just opening a drawing to extract something, or look at something. No changes are made, but now it will be purged and saved with a new date.

Message 12 of 15
Lee_Mac
in reply to: alanjt_


alanjt_ wrote:

So, what happens if the user is just opening a drawing to extract something, or look at something. No changes are made, but now it will be purged and saved with a new date.


Ok, to account for the remote possibility that DBMOD remains unchanged:

 

(vl-load-com)
(if (null *editor-reactor*)
    (setq *editor-reactor* (vlr-editor-reactor nil '((:vlr-beginclose . purgedwg))))
)
(defun purgedwg ( reactor params )
    (if (null *acdoc*)
        (setq *acdoc* (vla-get-activedocument (vlax-get-acad-object)))
    )
    (if
        (and
            (= 1 (getvar 'DWGTITLED))
            (= 0 (getvar 'DBMOD))
            (equal (getvar 'TDUPDATE) (getvar 'DATE) (/ 5.0 86400.))
        )
        (progn
            (repeat 3 (vla-purgeall *acdoc*))
            (vla-save *acdoc*)
        )
    )
    (princ)
)
(princ)

 

Message 13 of 15
alanjt_
in reply to: Lee_Mac

Far from a remote possibility.

 

Hell, open a set of drawings just for printing purposes, but users taking objects from one drawing (that remains unedited) is a normal occurance.

Message 14 of 15
Lee_Mac
in reply to: alanjt_

Well anyway, its accounted for

Message 15 of 15
alanjt_
in reply to: Lee_Mac

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

Post to forums  

Autodesk Design & Make Report

”Boost