TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Amsterdammed on May 28, 2005, 09:24:00 AM

Title: reactor triggered when Autocad is exiting
Post by: Amsterdammed on May 28, 2005, 09:24:00 AM
I need to write some accounting program that writes to a log file what the designers are doing during a day. In the end of the day they should be offered a dialog box with all the files they worked on this day and the editing time they spend.

So they can fill in what they did with the file and all this will be written to a Dbase in Excel (not everybody in our company has MS-Access).

My Question is if there is a reactor that is triggered by closing Acad. I tried with a command reactor and the command “quit”. Would work, but than you have to leave Acad by typing Quit, what nobody does.

Is there some smart solution??
Title: reactor triggered when Autocad is exiting
Post by: Kerry on May 28, 2005, 08:05:26 PM
Google or Google GROUPS for
vlr-beginClose Mishler OR Menzi OR Puckett OR Luis OR Schneider


The results will be equal to the best you will find anywhere
Title: reactor triggered when Autocad is exiting
Post by: Jürg Menzi on May 29, 2005, 06:35:16 AM
Hi Amsterdammed

I've prepared an AcadDoc.lsp sample to write into a logfile. The only thing you've to do is to add your code inside the 'MeWriteToLogFile' function.
Code: [Select]
;
; == AcadDoc.lsp ==============================================================
; Initialize a Document Reactor to write a logfile on closing a document.
; Copyright:
;   ©2005 MENZI ENGINEERING GmbH, Switzerland
; Notes:
;   - None
;
; - Initialize ActiveX support
(vl-load-com)
;
; - Reactors ------------------------------------------------------------------
;
; - If not set, initialize DocManager-Reactor
(or Me:ReaDma
 (setq Me:ReaDma (VLR-DocManager-Reactor
                  nil
                 '(
                   (:VLR-documentToBeDestroyed . MeDocToBeDestroyedCallbacks)
                  )
                 )
 )
)
;
; - Notifications -------------------------------------------------------------
;
; - DocToBeDestroyed notifications
(defun MeDocToBeDestroyedCallbacks (Rea Arg)
 (MeWriteToLogFile)
 (MeDoCloseStuff)
 (princ)
)
;
; - Subs ----------------------------------------------------------------------
;
; - Reactor cleanup function
(defun MeDoCloseStuff ( / VarLst)
 (setq VarLst (MeGetReaVars))
 (mapcar 'VLR-remove (mapcar 'eval VarLst))
 (mapcar '(lambda (l) (set l nil)) VarLst)
 (princ)
)
; - Collect global reactor variables
(defun MeGetReaVars ( / RetVal)
 (foreach memb (atoms-family 1)
  (if (wcmatch (strcase memb) "ME:REA*")
   (setq RetVal (cons memb RetVal))
  )
 )
 (mapcar 'read RetVal)
)
; - Write to logfile function
(defun MeWriteToLogFile ( / )
;;; Add yor 'WriteToLogFileCode'
 (princ)
)
 
(princ)
;
; == End AcadDoc.lsp ==========================================================


Cheers
Title: reactor triggered when Autocad is exiting
Post by: Kerry on May 29, 2005, 07:40:17 AM
hehehehe

.. Unless one of those Gentlemen write a specific routine for you. :)

.. and use  VLR-documentToBeDestroyed instead  :oops:
Title: reactor triggered when Autocad is exiting
Post by: Jürg Menzi on May 29, 2005, 09:14:28 AM
Quote from: Kerry Brown
Unless one of those Gentlemen write a specific routine for you.
Taking my standard sample, have done some modifications and voilà... :mrgreen:
Title: reactor triggered when Autocad is exiting
Post by: Amsterdammed on May 29, 2005, 10:26:20 AM
Quote from: Kerry Brown
Google or Google GROUPS for
vlr-beginClose Mishler OR Menzi OR Puckett OR Luis OR Schneider


The results will be equal to the best you will find anywhere


Thank's.
I had to realise on Google that what i really want (to get an event on closing Autocad, not the drawings, this i allready covered) does no exist.

I wanted on the end of the working day (exit Acad) that a dialogbox appears.

I will have to get another way, I guess.

 :roll: [/quote]
Title: reactor triggered when Autocad is exiting
Post by: Amsterdammed on May 29, 2005, 10:29:57 AM
Quote from: Kerry Brown
hehehehe

.. Unless one of those Gentlemen write a specific routine for you. :)

.. and use  VLR-documentToBeDestroyed instead  :oops:


Nice, yes. But that is what you get when you are lazy. :wink:
Title: reactor triggered when Autocad is exiting
Post by: Amsterdammed on May 29, 2005, 10:31:20 AM
Quote from: Jürg Menzi
Quote from: Kerry Brown
Unless one of those Gentlemen write a specific routine for you.
Taking my standard sample, have done some modifications and voilà... :mrgreen:


Gruezzi in die Schwitz :D
Title: Re: reactor triggered when Autocad is exiting
Post by: MP on May 29, 2005, 11:09:01 AM
Quote from: Amsterdammed
My Question is if there is a reactor that is triggered by closing Acad. I tried with a command reactor and the command “quit”. Would work, but than you have to leave Acad by typing Quit, what nobody does.

What do you mean by close? If you mean by clicking the terminate icon:

(http://www.theswamp.org/screens/mp/terminate.png)

the quit event is still fired. Try it:

Code: [Select]
(if (/= 'VLR-Command-Reactor (type ReactorCommandWillStart))
    (setq ReactorCommandWillStart
        (vlr-command-reactor nil
           '((:vlr-commandWillStart . CallbackCommandWillStart))
        )
    )
)

(defun CallbackCommandWillStart ( reactor cmdInfo / cmdName )
    (cond
        (   (eq "QUIT" (setq cmdName (car cmdInfo)))
            (alert "When you press [ Ok ] AutoCAD will vanish.")
        )
    )
)

Note: I tested this rather quickly in AutoCAD 2006.
Title: Re: reactor triggered when Autocad is exiting
Post by: Amsterdammed on May 30, 2005, 07:45:09 AM
Quote from: MP

Note: I tested this rather quickly in AutoCAD 2006.


Thank's MP  :roll:

I thought the same, the event is the same, only started by the button in the window's corner.

You are right, the code works in R2006, but not in R2002. So i will find out when our company makes the move to Acad 2006 (I have it already for development reasons, i'm considered as the one eyed in the "Kingdom of the blind" known as the Company I'm working for ). If it is in the near future, I'll be fine, otherwise I will try something with closing the last open drawing (a sign you wanna quit acad, too, i guess)


Thanks for the help, MP  :D
Title: reactor triggered when Autocad is exiting
Post by: MP on May 30, 2005, 08:27:03 AM
Perhaps you could hook into the documentToBeDestroyed event and fire your logging app when the documents count is 1. You may have to do some exprimentation with the count property to see when it truly represents the "AutoCAD is about to leave the building" event, notwithstanding the state of the sdi system variable.

Also, have you tried to find out if any command event is thrown when it's AutoCAD is terminating? Like --

Code: [Select]
(if (/= 'VLR-Command-Reactor (type ReactorCommandWillStart))
    (setq ReactorCommandWillStart
        (vlr-command-reactor nil
           '((:vlr-commandWillStart . CallbackCommandWillStart))
        )
    )
)

(defun CallbackCommandWillStart ( reactor cmdInfo / cmdName )
    (cond
        (   (eq "QUIT" (setq cmdName (car cmdInfo)))
            (alert "When you press [ Ok ] AutoCAD will vanish.")
        )
        (   cmdName
            (alert
                (strcat
                    "<"
                    cmdName
                    "> Command called."
                )    
            )
        )
    )
)

Hope this makes sense, just woke up and still kinda groggy.

(http://www.theswamp.org/screens/mp/mpzzz.gif)
Title: reactor triggered when Autocad is exiting
Post by: Jeff_M on May 30, 2005, 12:58:27 PM
You might want to look into the VBA Event "BeginQuit". It fires when Acad is closed by any method, other than a crash...
Title: reactor triggered when Autocad is exiting
Post by: Amsterdammed on May 30, 2005, 01:05:58 PM
Quote from: Jeff_M
You might want to look into the VBA Event "BeginQuit". It fires when Acad is closed by any method, other than a crash...


So i will have to do the whole thing in VBA ? :?:
Title: reactor triggered when Autocad is exiting
Post by: Jeff_M on May 30, 2005, 02:51:12 PM
Yes, I believe so. But don't be afraid to give it a try and ask lots of questions. There are plenty of folks here that can help you in that direction, too.

Michael, your code returns nothing if the "X" is clicked to close Acad2002 :?
Title: reactor triggered when Autocad is exiting
Post by: Amsterdammed on May 30, 2005, 08:02:37 PM
Quote from: Jeff_M
Yes, I believe so. But don't be afraid to give it a try and ask lots of questions. There are plenty of folks here that can help you in that direction, too.

Michael, your code returns nothing if the "X" is clicked to close Acad2002 :?

Thanks Jeff, I did some VBA stuff, but mostly in Excel and in Acad only when i needed to get a link to Excel. Is there a  VBA command that would do the same as Vbarun in lisp, like starting a lispfile from VBA?
Title: reactor triggered when Autocad is exiting
Post by: MP on May 31, 2005, 07:06:35 AM
Quote from: Jeff_M
Michael, your code returns nothing if the "X" is clicked to close Acad2002 :?

Thanks for confirming Jeff.