Author Topic: Need to apply a lisp routine to AutoCAD Close  (Read 4509 times)

0 Members and 1 Guest are viewing this topic.

tbrock

  • Guest
Need to apply a lisp routine to AutoCAD Close
« 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.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Need to apply a lisp routine to AutoCAD Close
« Reply #1 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.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Need to apply a lisp routine to AutoCAD Close
« Reply #2 on: January 12, 2011, 03:09:31 AM »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

kruuger

  • Swamp Rat
  • Posts: 637
Re: Need to apply a lisp routine to AutoCAD Close
« Reply #3 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

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Need to apply a lisp routine to AutoCAD Close
« Reply #4 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.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Need to apply a lisp routine to AutoCAD Close
« Reply #5 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 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

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Need to apply a lisp routine to AutoCAD Close
« Reply #6 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?  ;-)
James Buzbee
Windows 8

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Need to apply a lisp routine to AutoCAD Close
« Reply #7 on: January 12, 2011, 11:44:22 AM »
DosLib also provides this ability.

tbrock

  • Guest
Re: Need to apply a lisp routine to AutoCAD Close
« Reply #8 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.

kruuger

  • Swamp Rat
  • Posts: 637
Re: Need to apply a lisp routine to AutoCAD Close
« Reply #9 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 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

tbrock

  • Guest
Re: Need to apply a lisp routine to AutoCAD Close
« Reply #10 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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Need to apply a lisp routine to AutoCAD Close
« Reply #11 on: January 12, 2011, 07:27:14 PM »
You can't use command calls with a reactor.

tbrock

  • Guest
Re: Need to apply a lisp routine to AutoCAD Close
« Reply #12 on: January 13, 2011, 01:55:08 PM »
Everything working properly now. Thanks again for all your help.