TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: tbrock on January 12, 2011, 01:50:20 AM

Title: Need to apply a lisp routine to AutoCAD Close
Post by: tbrock on January 12, 2011, 01:50:20 AM
Not sure how to go a bout this, but I have a lisp routine I need to run every time AutoCAD Closes. Not sure if a macro can be created to do this? How do I intercept what happens when a user clicks the red x in the corner to close? Thanx in advance for your help.
Title: Re: Need to apply a lisp routine to AutoCAD Close
Post by: Keith™ on January 12, 2011, 02:35:03 AM
Well, in pure lisp it can't be done, it "might" be able to be done using a reactor and vlisp, but I'm not so sure I'd try to do it myself.
Title: Re: Need to apply a lisp routine to AutoCAD Close
Post by: Kerry on January 12, 2011, 03:09:31 AM

Have a look at this perhaps
http://www.theswamp.org/index.php?topic=5361.msg65445#msg65445
Title: Re: Need to apply a lisp routine to AutoCAD Close
Post by: kruuger on January 12, 2011, 06:56:44 AM
Code: [Select]
[color=RED]([/color][color=BLUE]defun[/color] [color=BLUE]TimecardCloseReactor[/color] [color=RED]()[/color]
  [color=RED]([/color][color=BLUE]vl-load-com[/color][color=RED])[/color]
  [color=RED]([/color][color=BLUE]setq[/color] [color=BLUE]react[/color]
    [color=RED]([/color][color=BLUE]vlr-editor-reactor[/color] data
      [color=RED]([/color][color=BLUE]list[/color]
        [color=RED]([/color][color=BLUE]cons[/color] [color=BLUE]:vlr-beginclose[/color] [color=DARKRED]'[/color][color=BLUE]CloseCallBack[/color][color=RED])[/color]
      [color=RED])[/color]
    [color=RED])[/color]
  [color=RED])[/color]
[color=RED])[/color]

[color=RED]([/color][color=BLUE]defun[/color] [color=BLUE]CloseCallBack[/color] [color=RED]([/color]reactor arguments [color=BLUE]/[/color] AcadApp ActiveDocument documents ile_doc DCL ACT[color=RED])[/color]
  [color=RED]([/color][color=BLUE]progn[/color]
    [color=RED]([/color][color=BLUE]setq[/color] AcadApp [color=RED]([/color][color=BLUE]vlax-get-acad-object[/color][color=RED])[/color]
          ActiveDocument [color=RED]([/color][color=BLUE]vla-get-activedocument[/color] AcadApp[color=RED])[/color]
          documents [color=RED]([/color][color=BLUE]vlax-get-property[/color] AcadApp [color=DARKRED]'[/color]Documents[color=RED])[/color]
          ile_doc [color=RED]([/color][color=BLUE]vlax-get-property[/color] [color=RED]([/color][color=BLUE]vlax-get-property[/color] AcadApp [color=DARKRED]'[/color]Documents[color=RED])[/color] [color=DARKRED]'[/color]Count[color=RED])[/color]
    [color=RED])[/color]
    [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]<=[/color] ile_doc [color=#009900]1[/color][color=RED])[/color]
      [color=RED]([/color][color=BLUE]progn[/color]
        [color=RED]([/color][color=BLUE]setq[/color] DCL [color=RED]([/color][color=BLUE]load_dialog[/color] [color=#a52a2a]"Timecard Reactor.dcl"[/color][color=RED]))[/color]
        [color=RED]([/color][color=BLUE]new_dialog[/color] [color=#a52a2a]"TC"[/color] DCL[color=RED])[/color]
        [color=RED]([/color][color=BLUE]mode_tile[/color] [color=#a52a2a]"TT"[/color] [color=#009900]2[/color][color=RED])[/color]
        [color=RED]([/color][color=BLUE]action_tile[/color] [color=#a52a2a]"OK"[/color] [color=#a52a2a]"(done_dialog 1)"[/color][color=RED])[/color]
        [color=RED]([/color][color=BLUE]setq[/color] ACT [color=RED]([/color][color=BLUE]start_dialog[/color][color=RED]))[/color]
        [color=RED]([/color][color=BLUE]unload_dialog[/color] DCL[color=RED])[/color]
      [color=RED])[/color]
    [color=RED])[/color]
  [color=RED])[/color]
[color=RED])[/color]

[color=RED]([/color][color=BLUE]TimecardCloseReactor[/color][color=RED])[/color]

[color=RED]([/color][color=BLUE]princ[/color][color=RED])[/color]
maybe this. i'm using this to popup some alert when last drawing is closed.
kruuger
Title: Re: Need to apply a lisp routine to AutoCAD Close
Post by: dgorsman on January 12, 2011, 10:29:12 AM
Its possible with a reactor, but any code that executes *must* be quick.  The application doesn't pause while the reactor-called code executes, so its entirely possible for the application to hang since something is still running when it tries to finally exit.
Title: Re: Need to apply a lisp routine to AutoCAD Close
Post by: Lee Mac on January 12, 2011, 10:32:39 AM
maybe this. i'm using this to popup some alert when last drawing is closed.
kruuger

Kruuger,

Did you use my LISPStyler (http://www.theswamp.org/index.php?topic=36508.0) to add colour to the code? If so, use the program on the code in a new drawing in which the namespace is clear of variables used in the code, else these will be coloured.

Also, look at the 'exceptions' section of the code  :-)

Lee
Title: Re: Need to apply a lisp routine to AutoCAD Close
Post by: jbuzbee on January 12, 2011, 11:11:12 AM
<Theroy Mode On>

An OpenDCL modeless form could be used: the OnEnteringNoDocState event will fire as the drawing(s) is(are) about to close.  The form could be invisible and loaded from a .mnl file or acad.lsp.

</Theroy Mode Off>

Hey, you new that was comming, right?  ;-)
Title: Re: Need to apply a lisp routine to AutoCAD Close
Post by: cmwade77 on January 12, 2011, 11:44:22 AM
DosLib also provides this ability.
Title: Re: Need to apply a lisp routine to AutoCAD Close
Post by: tbrock on January 12, 2011, 01:18:31 PM
Thanks to all for the help!!!

Kruuger, huge help on understanding that reactor code.
Working like a charm now.
Added a modified version of this into my main lisp that loads every time I open ACAD.
Runs perfectly.

Again, thanks so much.
Title: Re: Need to apply a lisp routine to AutoCAD Close
Post by: kruuger on January 12, 2011, 02:26:06 PM
maybe this. i'm using this to popup some alert when last drawing is closed.
kruuger

Kruuger,

Did you use my LISPStyler (http://www.theswamp.org/index.php?topic=36508.0) to add colour to the code? If so, use the program on the code in a new drawing in which the namespace is clear of variables used in the code, else these will be coloured.

Also, look at the 'exceptions' section of the code  :-)

Lee
Hi Lee,
Yes, I want to see how it works. I just use default color settings. Looks great.
Thanks for tips.
kruuger
Title: Re: Need to apply a lisp routine to AutoCAD Close
Post by: tbrock on January 12, 2011, 04:21:56 PM
Spoke a little too soon.
Everything works except for a command line part of the called lisp routine that changes the loaded menu.
So.....   

I can't seem to make any command line functions work once this reactor has been triggered.
Anybody have an alternate way of changing the menu?
The original line of code was (command "menu" "acad")
very simple but useless if i can't use command  line functions.
Anyone?

Thx in advance.
Title: Re: Need to apply a lisp routine to AutoCAD Close
Post by: Lee Mac on January 12, 2011, 07:27:14 PM
You can't use command calls with a reactor.
Title: Re: Need to apply a lisp routine to AutoCAD Close
Post by: tbrock on January 13, 2011, 01:55:08 PM
Everything working properly now. Thanks again for all your help.