×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Time Logging ... Need some help w/ code

Time Logging ... Need some help w/ code

Time Logging ... Need some help w/ code

(OP)
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) 

RE: Time Logging ... Need some help w/ code

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?


RE: Time Logging ... Need some help w/ code

(OP)
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
==============================================================

RE: Time Logging ... Need some help w/ code

(OP)
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

RE: Time Logging ... Need some help w/ code

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 -->

(setq filedef (findfile "C:\\Users\\Acad2015\\TimeLog\\Logfile.txt"))
   (if (not filedef)
	(open "C:\\Users\\Acad2015\\TimeLog\\Logfile.txt" "w") 

RE: Time Logging ... Need some help w/ code

(OP)
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 !!

RE: Time Logging ... Need some help w/ code

(OP)
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) 

RE: Time Logging ... Need some help w/ code

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)
   (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))
   (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 2 0)
      mt (rtos mt 2 1) 
   );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
;;;*-------------------------------------------
;;;*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;;;*-------------------------------------------
;;;*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) 

RE: Time Logging ... Need some help w/ code

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close