Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Contributor
alan1959
Posts: 25
Registered: ‎12-14-2011
Message 1 of 15 (265 Views)

Purge on Exit

265 Views, 14 Replies
01-10-2012 01:32 PM

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.

*Expert Elite*
Lee_Mac
Posts: 1,227
Registered: ‎12-29-2009
Message 2 of 15 (261 Views)

Re: Purge on Exit

01-10-2012 01:55 PM 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)

 

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Contributor
alan1959
Posts: 25
Registered: ‎12-14-2011
Message 3 of 15 (259 Views)

Re: Purge on Exit

01-10-2012 01:58 PM in reply to: alan1959

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

*Expert Elite*
Lee_Mac
Posts: 1,227
Registered: ‎12-29-2009
Message 4 of 15 (252 Views)

Re: Purge on Exit

01-10-2012 02:07 PM 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

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
*Expert Elite*
Patchy
Posts: 6,273
Registered: ‎09-16-2009
Message 5 of 15 (247 Views)

Re: Purge on Exit

01-10-2012 02:17 PM 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

*Expert Elite*
Lee_Mac
Posts: 1,227
Registered: ‎12-29-2009
Message 6 of 15 (241 Views)

Re: Purge on Exit

01-10-2012 02:34 PM 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.

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Contributor
alan1959
Posts: 25
Registered: ‎12-14-2011
Message 7 of 15 (237 Views)

Re: Purge on Exit

01-10-2012 03:10 PM 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.

*Expert Elite*
Lee_Mac
Posts: 1,227
Registered: ‎12-29-2009
Message 8 of 15 (210 Views)

Re: Purge on Exit

01-11-2012 04:20 AM 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)

 

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Valued Mentor
alanjt_
Posts: 483
Registered: ‎08-25-2008
Message 9 of 15 (202 Views)

Re: Purge on Exit

01-11-2012 07:30 AM 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.

*Expert Elite*
Lee_Mac
Posts: 1,227
Registered: ‎12-29-2009
Message 10 of 15 (191 Views)

Re: Purge on Exit

01-11-2012 09:22 AM 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...


 

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

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.