Author Topic: Timesheet lisp  (Read 3680 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Timesheet lisp
« on: May 29, 2006, 07:38:40 AM »
I use this lisp to keep track of files i work on, whenever i hit save it writes the details to a log file.

While I find it indispensable for keeping track of my work over the week, for timesheet purposes, it's quite big, every time i hit save, it writes a line containg the time date and drawing details.

How could I change this so that it only kept a log of each drawing once?

Code: [Select]
(DEFUN C:QSAVEIT ()
(setq V1 (menucmd "M=$(edtime, $(getvar,date),DDDD)")
      TM (menucmd "M=$(edtime, $(getvar,date),hh:mm:ss)")
      MO (menucmd "M=$(edtime, $(getvar,date),MOnth)")
      DAY (menucmd "M=$(edtime, $(getvar,date),DD)")
      YR (menucmd "M=$(edtime, $(getvar,date),yyyy)")
      DP (STRCAT (getvar "dwgprefix") (getvar "dwgname"))
      DATE (strcat V1 ", " MO " " DAY ", " YR " " TM " - " DP))
      (setq logfile "c:\\logfiles\\LOGFILE.TXT") ;<- set logfile name to variable
  (if (findfile logfile) ;<- check to see if logfile exists
    (setq TX (open "c:\\logfiles\\LOGFILE.TXT" "a")) ;<- if exists, append to log file
    (setq TX (open "c:\\logfiles\\LOGFILE.TXT" "w"));<- if does not exist, create file
    )
    (write-line Date TX)
    (close TX)
  (COMMAND "QSAVE")
    (princ)
  )
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

kpblc

  • Bull Frog
  • Posts: 396
Re: Timesheet lisp
« Reply #1 on: May 29, 2006, 08:09:21 AM »
Try something like this:
Code: [Select]
(defun c:qsavelog (/ v1 tm mo day yr dp file_name file_handle *error*)
  (defun *error* (msg)
    (if file_handle
      (close file_handle)
      ) ;_ end of if
    (princ msg)
    (princ)
    ) ;_ end of defun
  (setq v1     (menucmd "M=$(edtime, $(getvar,date),DDDD)")
tm     (menucmd "M=$(edtime, $(getvar,date),hh:mm:ss)")
mo     (menucmd "M=$(edtime, $(getvar,date),MOnth)")
day     (menucmd "M=$(edtime, $(getvar,date),DD)")
yr     (menucmd "M=$(edtime, $(getvar,date),yyyy)")
dp     (strcat (getvar "dwgprefix") (getvar "dwgname"))
file_name   (strcat "c:\\logs\\" (vl-filename-base (getvar "dwgname")) ".log")
file_handle (open file_name
  (if (findfile file_name)
    "w"
    "a"
    ) ;_ end of if
  ) ;_ end of open
) ;_ end of setq
  (write-line (strcat v1 ", " mo " " day ", " yr " " tm " - " dp) file_handle)
  (close file_handle)
  (command "_.qsave")
  ) ;_ end of defun
Sorry for my English.

sinc

  • Guest
Re: Timesheet lisp
« Reply #2 on: May 29, 2006, 10:11:02 AM »
Or just call your logging routine from ACADDOC.LSP, and log every time you open a drawing.

That will make sure you get an entry even when Autocad crashes.

nivuahc

  • Guest
Re: Timesheet lisp
« Reply #3 on: May 30, 2006, 10:34:10 AM »
This is what I've been using for a while. It's in my MNL file and the end of the MNL file has a simple

Code: [Select]
(cadlog)

Code: [Select]
(defun cadlog (/ 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")
log_file  (open (strcat "z:\\" user_name "_cadlog.txt") "a")
  )
  (write-line
    (strcat (thedate open_time "-")
    " at "
    (thetime open_time nil)
    " "
    job_no
    dwg_no
    )
    log_file
  )
  (close log_file)
)


(defun thedate (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)
  sep1
  (substr date1 7 2)
  sep1
  (substr date1 1 4)
  )
) ;_ end defun thedate



(defun thetime (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 thetime

It creates a text file on the users network drive (Z: in our case) called username_cadlog.txt which is filled with output like this:

Code: [Select]
05-30-2006 at 07:37:13 P:\05038 West Lake Club House\dwgs\E3.5.dwg

hudster

  • Gator
  • Posts: 2848
Re: Timesheet lisp
« Reply #4 on: May 30, 2006, 11:21:36 AM »
Does that keep a copy of every drawing you open? or just what you save?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

nivuahc

  • Guest
Re: Timesheet lisp
« Reply #5 on: May 30, 2006, 12:04:44 PM »
Every drawing you open

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Timesheet lisp
« Reply #6 on: May 30, 2006, 12:29:00 PM »
Try this....I localized some of your variables and wrote to a global variable so when you save more than once in the same drawing session, it will only write to the log the first time.

Code: [Select]
(DEFUN C:QSAVEIT (/ V1 TM MO DAY YR DP DATE logfile TX);;;Localized variables
  (vl-load-com)
  (setq V1   (menucmd "M=$(edtime, $(getvar,date),DDDD)")
TM   (menucmd "M=$(edtime, $(getvar,date),hh:mm:ss)")
MO   (menucmd "M=$(edtime, $(getvar,date),MOnth)")
DAY  (menucmd "M=$(edtime, $(getvar,date),DD)")
YR   (menucmd "M=$(edtime, $(getvar,date),yyyy)")
DP   (STRCAT (getvar "dwgprefix") (getvar "dwgname"))
DATE (strcat V1 ", " MO " " DAY ", " YR " " TM " - " DP)
  )
  (setq logfile "c:\\logfiles\\LOGFILE.TXT")
  (if (= *alreadysaved* nil);;;Check to see if log has been written in this drawing session
    (progn
      (setq *alreadysaved* T);;;Sets global varial to T
      (if (findfile logfile)
(setq TX (open logfile "a"))
(progn
  (vl-mkdir "c:\\logfiles");;;Makes directory
  (setq TX (open logfile "w"))
)
      )
      (write-line Date TX);;;Write to text file
      (close TX);;;Close text file
    )
    (princ
      "\n Drawing saved...log has already been written to this session."
    )
  )
  (vla-save
    (vla-get-activedocument (vlax-get-acad-object))
  );;;ActiveX save to eliminate command
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

hudster

  • Gator
  • Posts: 2848
Re: Timesheet lisp
« Reply #7 on: May 31, 2006, 03:26:32 AM »
Thats brilliant ronjop, I was thinking about loooking throught the text file and deleting duplicate entries, but that way is a lot better.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Timesheet lisp
« Reply #8 on: May 31, 2006, 07:00:37 AM »
Thats brilliant ronjop, I was thinking about loooking throught the text file and deleting duplicate entries, but that way is a lot better.

Glad you like it :).

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC