Dommy,
I had the same Problem a while ago and Juerg Menzi wrote some great solution which works with a timeout function, so only when you WORK it will count the time.
;== AcadDoc.lsp ==============================================================
; Sets Command Reactors to collect the command time.
; Sets a DocManager Reactor to release the Reactor objects at the end
; of an AutoCAD session.
; Copyright:
; ©2005 MENZI ENGINEERING GmbH, Switzerland
; Notes:
; - None
; - Initialize ActiveX support
(vl-load-com)
;
; - Initialize session variables
;
(setq Me:DwgNme "" ;empty drawing name
Me:CmdTim 0 ;command time
Me:CmdTmp 0 ;temporary command time
Me:CmdCnt 0 ;command count
Me:TimOut 180 ;command timeout
)
;
; - Reactors ------------------------------------------------------------------
;
; - If not set, initialize DocManager-Reactor
(or Me:ReaDma
(setq Me:ReaDma (VLR-DocManager-Reactor
nil
'(
(:VLR-documentToBeDestroyed . MeDocToBeDestroyedCallbacks)
)
)
)
)
; - If not set, initialize DWG-Reactor
(or Me:ReaDwg
(setq Me:ReaDwg (VLR-DWG-Reactor
nil
'(
(:VLR-SaveComplete . MeDwgSaveCompleteCallbacks)
)
)
)
)
; - If not set, initialize Command-Reactor
(or Me:ReaCom
(setq Me:ReaCom (VLR-Command-Reactor
nil
'(
(:VLR-commandWillStart . MeCommandWillStartCallbacks)
(:VLR-commandEnded . MeCommandEndedCallbacks)
(:VLR-commandCancelled . MeCommandCancelledCallbacks)
)
)
)
)
;
; - Notifications -------------------------------------------------------------
;
; - MeDwgSaveComplete notifications
(defun MeDwgSaveCompleteCallbacks (Rea Arg)
(MeDoDwgSaveCompleteStuff Arg)
(princ)
)
; - CommandWillStart notifications
(defun MeCommandWillStartCallbacks (Rea Arg)
(MeDoCmdWillStartStuff Arg)
(princ)
)
; - CommandEnded notifications
(defun MeCommandEndedCallbacks (Rea Arg)
(MeDoCmdEndedStuff Arg)
(princ)
)
; - CommandCancelled notifications
(defun MeCommandCancelledCallbacks (Rea Arg)
(MeDoCmdCancelledStuff Arg)
(princ)
)
; - DocToBeDestroyed notifications
(defun MeDocToBeDestroyedCallbacks (Rea Arg)
(MeWriteToLog)
(MeDoCloseStuff)
(princ)
)
;
; - Subs ----------------------------------------------------------------------
;
; - DWG save complete function
(defun MeDoDwgSaveCompleteStuff (Arg)
(setq Me:DwgNme (cadr Arg))
(princ)
)
; - Command will start function
(defun MeDoCmdWillStartStuff (Arg)
(setq Me:CmdTmp (getvar "MILLISECS")
Me:CmdCnt (1+ Me:CmdCnt)
)
(princ)
)
; - Command ended function
(defun MeDoCmdEndedStuff (Arg / TmpVal)
(setq TmpVal (- (getvar "MILLISECS") Me:CmdTmp)
Me:CmdTim (if (> TmpVal (* Me:TimOut 1000)) ;User is sleeping
Me:CmdTim
(+ TmpVal Me:CmdTim)
)
)
(princ)
)
; - Command cancelled function
(defun MeDoCmdCancelledStuff (Arg / TmpVal)
(setq TmpVal (- (getvar "MILLISECS") Me:CmdTmp)
Me:CmdTim (if (> TmpVal (* Me:TimOut 1000)) ;User was sleeping
Me:CmdTim
(+ TmpVal Me:CmdTim)
)
)
(princ)
)
;
; - Write to log function
(defun MeWriteToLog ()
(alert (strcat
"Drawing name:\t\t" Me:DwgNme
"\nTotal command time:\t" (MeCalcTime Me:CmdTim)
"\nTotal commands called:\t" (itoa Me:CmdCnt)
)
)
(princ)
)
; - 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)
)
; - Calculate time from msecs
(defun MeCalcTime (Val / TimHrs TimMin TimSec TmpVal)
(setq TmpVal (fix (/ Val 1000.0))
TimSec (rem TmpVal 60)
TmpVal (/ (- TmpVal TimSec) 60)
TimMin (rem TmpVal 60)
TimHrs (/ (- TmpVal TimMin) 60)
)
(strcat (itoa TimHrs) "h " (itoa TimMin) "m " (itoa TimSec) "s")
)
(princ)
; == End AcadDoc.lsp ==========================================================
I hope this helps you,
Bernd