;autocad time logger
;will log when a drawing is opened, closed and time worked in drawing to a excel file in the format
;of: **Opened 3/21/2008 8:00:00 C:\Projects\624.020\Workfiles\AS-BUILT\624.020-AB.dwg
; **Closed 3/21/2008 8:30:00 C:\Projects\624.020\Workfiles\AS-BUILT\624.020-AB.dwg 0.50
;once day is over, the easiest thing to do is sort cells by D, then C, then A
;log file will be saved to "c:\CADLOG\" as "username_03-21-2008cadlog.TXT"
;if the folder does not exist, it will be created

(setq begin_time (getvar "tdusrtimer"))

(vl-load-com)

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

(defun CallbackCommandWillStart ( reactor cmdInfo / cmdName )
(cond
( (eq "CLOSE" (setq cmdName (car cmdInfo)))
(CADLOG-close)
)
)
)

(defun cadlog-open (/ user_name job_no dwg_no open_time log_file)
(vl-mkdir "c:\\CADLOG\\")
(setq user_name (getvar "loginname")
job_no (getvar "dwgprefix")
dwg_no (getvar "dwgname")
open_time (getvar "cdate")
date_lbl (strcat (thedate3 open_time "_"))
log_file (open (strcat "C:\\CADLOG\\" user_name "-" date_lbl "-""cadlog.txt") "a")
);setq
(write-line
(strcat "**Opened\t"
(thedate3 open_time "-")
"\t"
(thetime3 open_time nil)
"\t"
job_no
dwg_no
)
log_file
)
(close log_file)
)

(defun cadlog-close (/ user_name job_no dwg_no open_time log_file)
(setq user_name (getvar "loginname")
job_no (getvar "dwgprefix")
dwg_no (getvar "dwgname")
open_time (getvar "cdate")
end_time (getvar "tdusrtimer")
date_lbl (strcat (thedate3 open_time "_"))
time_worked (rtos (/ (/(* (- end_time begin_time) 86400) 60) 60) 2 2)
log_file (open (strcat "C:\\CADLOG\\" user_name "-" date_lbl "-" "cadlog.txt") "a")
);setq
(write-line
(strcat "**Closed\t"
(thedate3 open_time "-")
"\t"
(thetime3 open_time nil)
"\t"
job_no
dwg_no
"\t"
time_worked
)
log_file
)
(close log_file)
)

(defun thedate3 (date1 sep1 /)
;;return the date as a string formatted like 03-06-2000
;;date1 = the date as returned by (getvar "cdate")
;;sep1 = the separator to be used (- of /)
(setq date1 (rtos date1 2 8))
(strcat (substr date1 5 2)
"-"
(substr date1 7 2)
"-"
(substr date1 1 4)
)
) ;_ end defun thedate3

(defun thetime3 (date1 dec1 /)
;;return the time as a string formatted like 14:23:55 or 14:23:55.35
;;date1 = the date as returned by (getvar "cdate")
;;dec1 = if t, include decimals of a second, else hh:mm:ss.
(setq date1 (rtos date1 2 8))
(if dec1
(strcat (substr date1 10 2)
":"
(substr date1 12 2)
":"
(substr date1 14 2)
"."
(substr date1 16 2)
)
(strcat (substr date1 10 2)
":"
(substr date1 12 2)
":"
(substr date1 14 2)
)
) ;_ end if
) ;_ end defun thetime3

(CADLOG-open)

;***************************************************************************************

Advertisements