Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Logging ... Need some help w/ code

Status
Not open for further replies.

Joeyg77

Computer
Apr 24, 2015
6
US
I need help with this code ... I need it to have a daily log. If you run the list it over writes the file already there. I need it to return the after every entry and then i need the file to generate the date so it will have a running log of files in the folder. Take a look and let me know
Thanks Joey G

Code:
;;;*This is a Drawing Log Routine that logs the date, time, &
;;;*Drawing Name of each Drawing Session. It writes a report
;;;*to an ASCII Text file (Log.Txt).
;;;*If you wish you can load Login.Lsp from your Acad.Lsp file,
;;;*and edit the Acad.mnu to call the Logout.Lsp routine before
;;;*Exiting, Quiting or starting a new drawing.
;;;*Author: Kenny Ramage
;;;*============================================================
(defun C:LOGIN ( / a c d file fp)
   (if (not file)
	(open "C:\\Users\\Acad2015\\TimeLog\\Logfile.txt" "w")
   );if
   (setq a (TODAY)
      TIME1 (TIME)
      c (getvar "DWGNAME")
      d (strcat "Drawing Started   " a "  -  " TIME1 "  -  " c)
   );setq
   (if (/= c "Drawing.dwg")
      (progn  
         (setq file (findfile "C:\\Users\\Acad2015\\TimeLog\\Logfile.txt")
            fp (open file "a")
         );setq
         (princ d fp)
         (princ "\n" fp)
         (close fp)
         (princ (strcat "\nLogged in at : " TIME1))
      );progn
   );if
   (princ)
);defun
;;;*-------------------------------------------------
(defun C:LOGOUT ( / a c d file fp)
   (setq a (TODAY)
      TIME2 (TIME)
      c (getvar "DWGNAME")
      d (strcat "Drawing Exit    " a "  -  " TIME2 "  -  " c)
   );setq
   (if (/= c "Drawing.dwg")
      (progn  
         (setq file (findfile "C:\\Users\\Acad2015\\TimeLog\\Logfile.txt")
            fp (open file "a")
         );setq
         (princ d fp)
         (princ "\n" fp)
         (close fp)
         (princ (strcat "\nLogged out at : " TIME2))
         (etime)
      );progn
   );if
   (princ)
);defun
;;;*-------------------------------------------------
(defun ETIME ( / hr1 m1 s1 tot1 hr2 m2 s2 tot2 total ht mt file fp)
   (setq hr1 (* 60 (* 60 (atof (substr time1 1 2))))
      m1 (* 60 (atof (substr time1 4 2)))
      s1 (atof (substr time1 7 2))
      tot1 (+ hr1 m1 s1)
      hr2 (* 3600 (atof (substr time2 1 2)))
      m2 (* 60 (atof (substr time2 4 2)))
      s2 (atof (substr time2 7 2))
      tot2 (+ hr2 m2 s2)
      total (- tot2 tot1)
      hr1 (/ total 3600)
      ht (fix hr1)
      hr1 (- hr1 ht)
      mt (* hr1 60)
      ht (rtos ht)
      mt (rtos mt) 
   );setq
   (setq d (strcat "Editing Time This Session :  " ht " Hours and " mt " minutes"))
   (setq file (findfile "C:\\Users\\Acad2015\\TimeLog\\Logfile.txt") 
      fp (open file "a")
   );setq
   (princ d fp)
   (princ "\n" fp)
   (princ "==============================================================" fp )
   (princ "\n" fp)
   (close fp)
   (princ)
);defun
;;;*-------------------------------------------
;;;*Calculates the Current Date
(defun TODAY ( / d yr mo day)
     (setq d (rtos (getvar "CDATE") 2 6)
          yr (substr d 3 2)
          mo (substr d 5 2)
         day (substr d 7 2)
     );setq
     (strcat mo "/" day "/" yr)
);defun
;;;*-------------------------------------------
;;;*Calculates the Current Time
(defun TIME ( / d hr m s)
     (setq d (rtos (getvar "CDATE") 2 6)
          hr (substr d 10 2)
           m (substr d 12 2)
           s (substr d 14 2)
     );setq
     (strcat hr ":" m ":" s)
);defun
(princ)
 
Replies continue below

Recommended for you

The code appears that it would "append" a timestamp to the log file every time you run the routine, rather than overwrite it.
Can you be more clear on what is happening, & what you want it to do?


 
Sorry Carl for the criptic message....
I need the lisp to generate a daily date so i can keep a daily log of what i worked on
[code} (open "C:\\Users\\Acad2015\\TimeLog\\Logfile-(date).txt" "w")[/code]

Then I will want the output text file to look like this ....

Drawing Started 04/24/15 - 08:53:19 - Holliday_Parlor_Rev0.dwg
Drawing Exit 04/24/15 - 08:53:43 - Holliday_Parlor_Rev0.dwg
Editing Time This Session : 0.0000 Hours and 0.4000 minutes
==============================================================

Drawing Started 04/24/15 - 08:53:19 - Holliday_LivingRm_Rev0.dwg
Drawing Exit 04/24/15 - 08:53:43 - Holliday_LivingRm_Rev0.dwg
Editing Time This Session : 0.0000 Hours and 0.4000 minutes
==============================================================
 
I think there needs to be a IF Then statement ... If there isnt a file write one .. if there is Append it

Because the 1st line of code is telling to write the file every time you run the login part of the lisp then every part after that it appends to it.

and the date part i just want it so I have a daily log ... and thanks Carl for the help if you can give it

Joey G
 
OK I see it does overwrite every time routine is reloaded.
It needs just a simple change.

Insert 1 line and edit one line.

Code:
 [highlight #FCE94F](setq filedef (findfile "C:\\Users\\Acad2015\\TimeLog\\Logfile.txt"))[/highlight]
   (if (not [highlight #FCE94F]filedef[/highlight])
	(open "C:\\Users\\Acad2015\\TimeLog\\Logfile.txt" "w")
 
is there a way to add the date to the logfile-(DATE).txt so everyday it will generate a textfile so it looks like this

Logfile-042415.txt ?

Thank you for that help !!! ... This is just perfect !!
 
Carl I need the code to look something like this ... so it puts the date into it .. if i add this to the code it says that todate isnt defined and i have no idea how to define it.

findfile "C:\\Users\\Acad2015\\TimeLog\\Logfile-" (toDate "DATE" "MODDYY") ".txt"))

This is the code i have so you can test it .... let me know .. Joey

Code:
;;;*This is a Drawing Log Routine that logs the date, time, &
;;;*Drawing Name of each Drawing Session. It writes a report
;;;*to an ASCII Text file (Log.Txt).
;;;*If you wish you can load Login.Lsp from your Acad.Lsp file,
;;;*and edit the Acad.mnu to call the Logout.Lsp routine before
;;;*Exiting, Quiting or starting a new drawing.
;;;*============================================================
(defun C:LOGIN ( / a c d file fp)
(setq filedef (findfile "C:\\Users\\Acad2015\\TimeLog\\Logfile-" (toDate "DATE" "MODDYY") ".txt"))
   (if (not filedef)
	(open ((strcat "C:\\Users\\Acad2015\\TimeLog\\Logfile-" (toDate "DATE" "MODDYY") ".txt") "a"))
   );if
   (setq a (TODAY)
      TIME1 (TIME)
      c (getvar "DWGNAME")
      d (strcat "Drawing Started   " a "  -  " TIME1 "  -  " c)
   );setq
   (if (/= c "Drawing.dwg")
      (progn  
         (setq file (findfile "C:\\Users\\Acad2015\\TimeLog\\Logfile-" (toDate "DATE" "MODDYY") ".txt")
            fp (open file "a")
         );setq
         (princ d fp)
         (princ "\n" fp)
         (close fp)
         (princ (strcat "\nLogged in at : " TIME1))
      );progn
   );if
   (princ)
);defun
;;;*-------------------------------------------------
(defun C:LOGOUT ( / a c d file fp)
   (setq a (TODAY)
      TIME2 (TIME)
      c (getvar "DWGNAME")
      d (strcat "Drawing Exit    " a "  -  " TIME2 "  -  " c)
   );setq
   (if (/= c "Drawing.dwg")
      (progn  
         (setq file (findfile "C:\\Users\\Acad2015\\TimeLog\\Logfile-" (todate "DATE" "MODDYY") ".txt")
            fp (open file "a")
         );setq
         (princ d fp)
         (princ "\n" fp)
         (close fp)
         (princ (strcat "\nLogged out at : " TIME2))
         (etime)
      );progn
   );if
   (princ)
);defun
;;;*-------------------------------------------------
(defun ETIME ( / hr1 m1 s1 tot1 hr2 m2 s2 tot2 total ht mt file fp)
   (setq hr1 (* 60 (* 60 (atof (substr time1 1 2))))
      m1 (* 60 (atof (substr time1 4 2)))
      s1 (atof (substr time1 7 2))
      tot1 (+ hr1 m1 s1)
      hr2 (* 3600 (atof (substr time2 1 2)))
      m2 (* 60 (atof (substr time2 4 2)))
      s2 (atof (substr time2 7 2))
      tot2 (+ hr2 m2 s2)
      total (- tot2 tot1)
      hr1 (/ total 3600)
      ht (fix hr1)
      hr1 (- hr1 ht)
      mt (* hr1 60)
      ht (rtos ht)
      mt (rtos mt) 
   );setq
   (setq d (strcat "Editing Time This Session :  " ht " Hours and " mt " minutes"))
   (setq file (findfile "C:\\Users\\Acad2015\\TimeLog\\Logfile-" (todate "DATE" "MODDYY") ".txt") 
      fp (open file "a")
   );setq
   (princ d fp)
   (princ "\n" fp)
   (princ "==============================================================" fp )
   (princ "\n" fp)
   (close fp)
   (princ)
);defun
;;;*-------------------------------------------
;;;*Calculates the Current Date
(defun TODAY ( / d yr mo day)
     (setq d (rtos (getvar "CDATE") 2 6)
          yr (substr d 3 2)
          mo (substr d 5 2)
         day (substr d 7 2)
     );setq
     (strcat mo "/" day "/" yr)
);defun
;;;*-------------------------------------------
;;;*Calculates the Current Time
(defun TIME ( / d hr m s)
     (setq d (rtos (getvar "CDATE") 2 6)
          hr (substr d 10 2)
           m (substr d 12 2)
           s (substr d 14 2)
     );setq
     (strcat hr ":" m ":" s)
);defun
(princ)
 
Here's a modified routine to create separate log file for each day.
Your edits had some lisp syntax problems, but the general approach works okay.

Code:
;;;*This is a Drawing Log Routine that logs the date, time, &
;;;*Drawing Name of each Drawing Session. It writes a report
;;;*to an ASCII Text file (Log.Txt).
;;;*If you wish you can load Login.Lsp from your Acad.Lsp file,
;;;*and edit the Acad.mnu to call the Logout.Lsp routine before
;;;*Exiting, Quiting or starting a new drawing.
;;;*Author: Kenny Ramage
;;;*============================================================
(defun C:LOGIN ( / a c d file fp FN_Path FN_Pref filedef)
   [highlight #FCE94F](setq FN_Path "C:\\Users\\Acad2015\\TimeLog\\")
   (setq FN_Pref "Logfile-")
   (setq FN_Full (strcat FN_Path FN_Pref (FN_Date) ".txt"))
   (setq filedef (findfile FN_Full))[/highlight]
   (if (not filedef)
       (open FN_Full "w")
   );if
   (setq a (TODAY)
      TIME1 (TIME)
      c (getvar "DWGNAME")
      d (strcat "Drawing Started   " a "  -  " TIME1 "  -  " c)
   );setq
   (if (/= c "Drawing.dwg")
      (progn  
         (setq file (findfile FN_Full)
            fp (open file "a")
         );setq
         (princ d fp)
         (princ "\n" fp)
         (close fp)
         (princ (strcat "\nLogged in at : " TIME1))
      );progn
   );if
   (princ)
);defun
;;;*-------------------------------------------------
(defun C:LOGOUT ( / a c d file fp)
   (setq a (TODAY)
      TIME2 (TIME)
      c (getvar "DWGNAME")
      d (strcat "Drawing Exit    " a "  -  " TIME2 "  -  " c)
   );setq
   (if (/= c "Drawing.dwg")
      (progn  
         (setq file (findfile FN_Full)
            fp (open file "a")
         );setq
         (princ d fp)
         (princ "\n" fp)
         (close fp)
         (princ (strcat "\nLogged out at : " TIME2))
         (etime)
      );progn
   );if
   (princ)
);defun
;;;*-------------------------------------------------
(defun ETIME ( / hr1 m1 s1 tot1 hr2 m2 s2 tot2 total ht mt file fp)
   (setq hr1 (* 60 (* 60 (atof (substr time1 1 2))))
      m1 (* 60 (atof (substr time1 4 2)))
      s1 (atof (substr time1 7 2))
      tot1 (+ hr1 m1 s1)
      hr2 (* 3600 (atof (substr time2 1 2)))
      m2 (* 60 (atof (substr time2 4 2)))
      s2 (atof (substr time2 7 2))
      tot2 (+ hr2 m2 s2)
      total (- tot2 tot1)
      hr1 (/ total 3600)
      ht (fix hr1)
      hr1 (- hr1 ht)
      mt (* hr1 60)
      ht (rtos ht [highlight #FCE94F]2 0[/highlight])
      mt (rtos mt [highlight #FCE94F]2 1[/highlight]) 
   );setq
   (setq d (strcat "Editing Time This Session :  " ht " Hours and " mt " minutes"))
   (setq file (findfile FN_Full) 
      fp (open file "a")
   );setq
   (princ d fp)
   (princ "\n" fp)
   (princ "==============================================================" fp )
   (princ "\n" fp)
   (close fp)
   (princ)
);defun
;;;*-------------------------------------------
;;;*Calculates the Current Date
(defun TODAY ( / d yr mo day)
     (setq d (rtos (getvar "CDATE") 2 6)
          yr (substr d 3 2)
          mo (substr d 5 2)
         day (substr d 7 2)
     );setq
     (strcat mo "/" day "/" yr)
);defun
;;;*-------------------------------------------
[highlight #FCE94F];;;*Calculates Current Date for file name
(defun FN_Date ( / d yr mo day)
     (setq d (rtos (getvar "CDATE") 2 6)
          yr (substr d 3 2)
          mo (substr d 5 2)
         day (substr d 7 2)
     );setq
     (strcat mo day yr)
);defun[/highlight];;;*-------------------------------------------
;;;*Calculates the Current Time
(defun TIME ( / d hr m s)
     (setq d (rtos (getvar "CDATE") 2 6)
          hr (substr d 10 2)
           m (substr d 12 2)
           s (substr d 14 2)
     );setq
     (strcat hr ":" m ":" s)
);defun
(princ)
 
Carl You my friend are AWESOME !!!! ...... Thank you for your help !

I hope this is something you can use also ... I made to icons for a start and stop and its PERFECT !!!

Thank you for the clean up and now i see how you defined it and its just spot on

Thanks again
Joey G
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top