TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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??
-
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
-
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.
;
; == 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
-
hehehehe
.. Unless one of those Gentlemen write a specific routine for you. :)
.. and use VLR-documentToBeDestroyed instead :oops:
-
Unless one of those Gentlemen write a specific routine for you.
Taking my standard sample, have done some modifications and voilà... :mrgreen:
-
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]
-
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:
-
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
-
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:
(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.
-
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
-
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 --
(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)
-
You might want to look into the VBA Event "BeginQuit". It fires when Acad is closed by any method, other than a crash...
-
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 ? :?:
-
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 :?
-
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?
-
Michael, your code returns nothing if the "X" is clicked to close Acad2002 :?
Thanks for confirming Jeff.