Jump to content

Recommended Posts

Hey everyone ... I need some help and I have noooo idea where to start or how to write the code needed to do my thought. I need a text file that gives a marker when you open and close a drawing w/ a time stamp and so i can track my day w/o trying to figure out how many hours I worked on a drawing. This has to be a continuous list for the day. There was a previous post from 2010 which worked great but it put an individual text file in each drawing location. I need one text file so i can see all the drawings that were opened and closed w/ the time & date..... So any help would be much appreciated

 

Joey G

Link to post
Share on other sites
  • Replies 31
  • Created
  • Last Reply

Top Posters In This Topic

  • JoeyG_77

    15

  • Commandobill

    10

  • BIGAL

    3

  • tzframpton

    2

I have no idea where to even begin ... This is the code i received from the forum

 

(defun TimeReac nil
(vl-load-com)
(if (not (vl-position "TIMEREACT"
(mapcar (function strcase)
(mapcar (function vlr-data)
(mapcar (function cadr)
(vlr-reactors :vlr-command-reactor))))))
(progn
(vlr-command-reactor "TIMEREACT"
(list
(cons :vlr-commandWillStart 'GetTime_C)
(cons :vlr-commandEnded 'GetTime_O)))

(princ "\n<< Reactor Initiated >>"))

(princ "\n<< Reactor Already Running >>"))

(princ))

(TimeReac)


(defun GetTime_O (Reactor Args)
(if (eq "OPEN" (strcase (car Args)))
(GetTime))
(princ))


(defun GetTime_C (Reactor Args)
(if (eq "CLOSE" (strcase (car Args)))
(GetTime))
(princ)) 


(defun GetTime (/ toDate *error* ofile)

(defun toDate (var format)
(menucmd (strcat "m=$(edtime,$(getvar," var ")," format ")")))

(defun *error* (msg)
(and ofile (close file))
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
(princ)) 

(if (setq ofile (open (strcat (getvar 'DWGPREFIX) (getvar 'DWGNAME) "_log.txt") "a"))
(progn 

(write-line (strcat "DATE: " (toDate "DATE" "DD.MO.YY HH.MM.SS")) ofile)
(write-line (strcat "DRAWING: " (getvar 'DWGPREFIX) (getvar 'DWGNAME)) ofile)
(write-line (strcat "CREATED: " (toDate "TDCREATE" "DD.MO.YY HH.MM.SS")) ofile)
(write-line (strcat "TOTAL EDITING TIME: " (toDate "TDINDWG" "HH.MM.SS") "\n") ofile)

(setq ofile (close ofile))))

(princ))



(defun c:TimeOFF (/ Reac)
(vl-load-com)
(if (and (setq Reac
(car
(vl-remove-if-not
(function
(lambda (x)
(eq "TIMEREACT" (strcase (vlr-data x)))))
(mapcar (function cadr)
(vlr-reactors :vlr-command-reactor)))))
(vlr-added-p Reac))
(progn
(vlr-remove Reac)
(princ "\n<< Reactor Deactivated >>"))

(princ "\n** Reactor Not Running **"))

(princ))

Link to post
Share on other sites
Commandobill

Ok, the line you want to change is this one:

(if (setq ofile (open (strcat (getvar 'DWGPREFIX) (getvar 'DWGNAME) "_log.txt") "a"))

 

If you let me know the exact location and file name I can change it for you. Otherwise, you would change :

(setq ofile (open (strcat (getvar 'DWGPREFIX) (getvar 'DWGNAME) "_log.txt") "a"))

to something like :

(setq ofile (open "C:\\somefilename.txt" "a"))

The double backslash is key.

Link to post
Share on other sites

C:\Users\Acad2015\TimeLog\Logfile.txt

also would this create a new file everyday .. its a silly question but still wanted to ask =)

Link to post
Share on other sites
Commandobill

Here's the new code:

;;I believe this was originally written by Lee-Mac
;;Date: Unknown
;;Modified By:Commandobill
;;Date 04/21/15
;;Reason for change: Updated to make text file be in a static position instead of dynamic.
(defun TimeReac nil
(vl-load-com)
(if (not (vl-position "TIMEREACT"
(mapcar (function strcase)
(mapcar (function vlr-data)
(mapcar (function cadr)
(vlr-reactors :vlr-command-reactor))))))
(progn
(vlr-command-reactor "TIMEREACT"
(list
(cons :vlr-commandWillStart 'GetTime_C)
(cons :vlr-commandEnded 'GetTime_O)))

(princ "\n<< Reactor Initiated >>"))

(princ "\n<< Reactor Already Running >>"))

(princ))

(TimeReac)


(defun GetTime_O (Reactor Args)
(if (eq "OPEN" (strcase (car Args)))
(GetTime))
(princ))


(defun GetTime_C (Reactor Args)
(if (eq "CLOSE" (strcase (car Args)))
(GetTime))
(princ)) 


(defun GetTime (/ toDate *error* ofile)

(defun toDate (var format)
(menucmd (strcat "m=$(edtime,$(getvar," var ")," format ")")))

(defun *error* (msg)
(and ofile (close file))
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
(princ)) 

(if (setq ofile (open "C:\\Users\\Acad2015\\TimeLog\\Logfile.txt" "a"));;Location of change
(progn 

(write-line (strcat "DATE: " (toDate "DATE" "DD.MO.YY HH.MM.SS")) ofile)
(write-line (strcat "DRAWING: " (getvar 'DWGPREFIX) (getvar 'DWGNAME)) ofile)
(write-line (strcat "CREATED: " (toDate "TDCREATE" "DD.MO.YY HH.MM.SS")) ofile)
(write-line (strcat "TOTAL EDITING TIME: " (toDate "TDINDWG" "HH.MM.SS") "\n") ofile)

(setq ofile (close ofile))))

(princ))



(defun c:TimeOFF (/ Reac)
(vl-load-com)
(if (and (setq Reac
(car
(vl-remove-if-not
(function
(lambda (x)
(eq "TIMEREACT" (strcase (vlr-data x)))))
(mapcar (function cadr)
(vlr-reactors :vlr-command-reactor)))))
(vlr-added-p Reac))
(progn
(vlr-remove Reac)
(princ "\n<< Reactor Deactivated >>"))

(princ "\n** Reactor Not Running **"))

(princ))

 

C:\Users\Acad2015\TimeLog\Logfile.txt

also would this create a new file everyday .. its a silly question but still wanted to ask =)

We could always change the code to create a new text file each day, but currently it does not.

Link to post
Share on other sites

This is the text from the file it gives

DATE: 04.21.15 13.05.26

DRAWING: X:\Churchill\Engineering\JohnsBedroom\ChurchHill_JohnsBedroom_Rev0.dwg

CREATED: 04.17.15 12.35.19

TOTAL EDITING TIME: 03.03.43

 

Bill is there a way to catch the action such as like ..

ACTION:OPEN

DATE: 04.21.15 13.05.26

DRAWING: X:\Churchill\Engineering\JohnsBedroom\ChurchHill_JohnsBedroom_Rev0.dwg

 

ACTION:CLOSED

DATE: 04.21.15 13.05.26

DRAWING: X:\Churchill\Engineering\JohnsBedroom\ChurchHill_JohnsBedroom_Rev0.dwg

Edited by JoeyG_77
MisTyped info
Link to post
Share on other sites
Commandobill

I'm sure there us a much more elegant way of doing this...

;;Author: Lee-Mac
;;Date: 01/27/10
;;Modified By:Commandobill
;;Date 04/21/15
;;Reason for change: Updated to make text file be in a static position instead of dynamic.
(defun TimeReac nil
 (vl-load-com)
 (if (not (vl-position "TIMEREACT"
     (mapcar (function strcase)
	     (mapcar (function vlr-data)
		     (mapcar (function cadr)
			     (vlr-reactors :vlr-command-reactor))))))
   (progn
     (vlr-command-reactor "TIMEREACT"
(list
  (cons :vlr-commandWillStart 'GetTime_C)
  (cons :vlr-commandEnded 'GetTime_O)))
     
     (princ "\n<< Reactor Initiated >>"))
   
   (princ "\n<< Reactor Already Running >>"))
 
 (princ))

(TimeReac)


(defun GetTime_O (Reactor Args)
 (if (eq "OPEN" (strcase (car Args)))
   (GetTime))
 (princ))


(defun GetTime_C (Reactor Args)
 (if (eq "CLOSE" (strcase (car Args)))
   (GetTime))
 (princ))


(defun GetTime (/ toDate *error* ofile)
 
 (defun toDate (var format)
   (menucmd (strcat "m=$(edtime,$(getvar," var ")," format ")")))
 
 (defun *error* (msg)
   (and ofile (close file))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
   (princ))
 
 (if (setq ofile (open "C:\\Logfile.txt" "a"));;Location of change
   (progn
     (if (eq "CLOSE" (strcase (car Args)))
(write-line "ACTION: CLOSED" ofile)
(write-line "ACTION: OPENED" ofile))
     (write-line (strcat "DATE: " (toDate "DATE" "DD.MO.YY HH.MM.SS")) ofile)
     (write-line (strcat "DRAWING: " (getvar 'DWGPREFIX) (getvar 'DWGNAME)) ofile)
     
     
     (setq ofile (close ofile))))
 
 (princ))



(defun c:TimeOFF (/ Reac)
 (vl-load-com)
 (if (and (setq Reac
	  (car
	    (vl-remove-if-not
	      (function
		(lambda (x)
		  (eq "TIMEREACT" (strcase (vlr-data x)))))
	      (mapcar (function cadr)
		      (vlr-reactors :vlr-command-reactor)))))
   (vlr-added-p Reac))
   (progn
     (vlr-remove Reac)
     (princ "\n<< Reactor Deactivated >>"))
   
   (princ "\n** Reactor Not Running **"))
 
 (princ))

Link to post
Share on other sites
Commandobill
Lol, sorry Bill. Just giving an alternative resource is all.

 

:)

 

Ha! I was just messing with you. I'm sure it's a good program.

Link to post
Share on other sites

Bob This is perfect !!! BUT !!! ... is there a way to add a space between each grouping =) This is the code I have .. Made some tweaks

;;Author: Lee-Mac
;;Date: 01/27/10
;;Modified By:Commandobill
;;Date 04/21/15
;;Reason for change: Updated to make text file be in a static position instead of dynamic.
(defun TimeReac nil
(vl-load-com)
(if (not (vl-position "TIMEREACT"
(mapcar (function strcase)
(mapcar (function vlr-data)
(mapcar (function cadr)
(vlr-reactors :vlr-command-reactor))))))
(progn
(vlr-command-reactor "TIMEREACT"
(list
(cons :vlr-commandWillStart 'GetTime_C)
(cons :vlr-commandEnded 'GetTime_O)))
     
(princ "\n<< Reactor Initiated >>"))
   
(princ "\n<< Reactor Already Running >>"))
 
(princ))

(TimeReac)


(defun GetTime_O (Reactor Args)
(if (eq "OPEN" (strcase (car Args)))
(GetTime))
(princ))


(defun GetTime_C (Reactor Args)
(if (eq "CLOSE" (strcase (car Args)))
(GetTime))
(princ))


(defun GetTime (/ toDate *error* ofile)
 
(defun toDate (var format)
(menucmd (strcat "m=$(edtime,$(getvar," var ")," format ")")))
 
(defun *error* (msg)
(and ofile (close file))
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
(princ))
 
(if (setq ofile (open "C:\\Users\\Acad2015\\TimeLog\\Logfile.txt" "a"));;Location of change
(progn
(if (eq "CLOSE" (strcase (car Args)))
(write-line "ACTION: CLOSED" ofile)
(write-line "ACTION: OPENED" ofile))
(write-line (strcat "DATE: " (toDate "DATE" "MO.DD.YY ** HH.MM.SS")) ofile)
(write-line (strcat "DRAWING: " (getvar 'DWGPREFIX) (getvar 'DWGNAME)) ofile)
     
     
(setq ofile (close ofile))))
 
(princ))



(defun c:TimeOFF (/ Reac)
(vl-load-com)
(if (and (setq Reac
(car
(vl-remove-if-not
(function
(lambda (x)
(eq "TIMEREACT" (strcase (vlr-data x)))))
(mapcar (function cadr)
(vlr-reactors :vlr-command-reactor)))))
(vlr-added-p Reac))
(progn
(vlr-remove Reac)
(princ "\n<< Reactor Deactivated >>"))
   
(princ "\n** Reactor Not Running **"))
 
(princ))

Edited by JoeyG_77
WRONG CODE !! .... SORRY BILL
Link to post
Share on other sites

This is the file I am getting ... Now

 

ACTION: OPENED

DATE: 04.21.15 15.22.02

DRAWING: X:\Churchill\Engineering\MasterBedroom208\ChurchHill_MasterBedroom208_Rev0.dwg

ACTION: OPENED

ACTION: OPENED

DATE: 04.21.15 TI4E 15.25.45

DRAWING: X:\Holliday 2\Engineering\Parlor\Holliday_Parlor_Rev0.dwg

ACTION: OPENED

DATE: 04.21.15 ** 15.26.43

DRAWING: X:\Holliday 2\Engineering\Parlor\Holliday_Parlor_SM.dwg

 

Is there a way to get it to look like this below ....

 

ACTION: OPENED

DATE: 04.21.15 15.22.02

DRAWING: X:\Churchill\Engineering\MasterBedroom208\ChurchHill_MasterBedroom208_Rev0.dwg

 

ACTION: OPENED

DATE: 04.21.15 TI4E 15.25.45

DRAWING: X:\Holliday 2\Engineering\Parlor\Holliday_Parlor_Rev0.dwg

 

ACTION: OPENED

DATE: 04.21.15 ** 15.26.43

DRAWING: X:\Holliday 2\Engineering\Parlor\Holliday_Parlor_SM.dwg

Link to post
Share on other sites

I have everything I need .... but i just need it to separate it in the log !! ..... its gotta be easy but i just dont know what is missing .

Link to post
Share on other sites
Commandobill

I forgot to add the "\n" for new line in the code. My bad.

;;Author: Lee-Mac
;;Date: 01/27/10
;;Modified By:Commandobill
;;Date 04/21/15
;;Reason for change: Updated to make text file be in a static position instead of dynamic.
(defun TimeReac nil
(vl-load-com)
(if (not (vl-position "TIMEREACT"
(mapcar (function strcase)
(mapcar (function vlr-data)
(mapcar (function cadr)
(vlr-reactors :vlr-command-reactor))))))
(progn
(vlr-command-reactor "TIMEREACT"
(list
(cons :vlr-commandWillStart 'GetTime_C)
(cons :vlr-commandEnded 'GetTime_O)))
     
(princ "\n<< Reactor Initiated >>"))
   
(princ "\n<< Reactor Already Running >>"))
 
(princ))

(TimeReac)


(defun GetTime_O (Reactor Args)
(if (eq "OPEN" (strcase (car Args)))
(GetTime))
(princ))


(defun GetTime_C (Reactor Args)
(if (eq "CLOSE" (strcase (car Args)))
(GetTime))
(princ))


(defun GetTime (/ toDate *error* ofile)
 
(defun toDate (var format)
(menucmd (strcat "m=$(edtime,$(getvar," var ")," format ")")))
 
(defun *error* (msg)
(and ofile (close file))
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
(princ))
 
(if (setq ofile (open "C:\\Users\\Acad2015\\TimeLog\\Logfile.txt" "a"));;Location of change
(progn
(if (eq "CLOSE" (strcase (car Args)))
(write-line "ACTION: CLOSED" ofile)
(write-line "ACTION: OPENED" ofile))
(write-line (strcat "DATE: " (toDate "DATE" "MO.DD.YY ** HH.MM.SS")) ofile)
(write-line (strcat "DRAWING: " (getvar 'DWGPREFIX) (getvar 'DWGNAME) "\n") ofile)
     
     
(setq ofile (close ofile))))
 
(princ))



(defun c:TimeOFF (/ Reac)
(vl-load-com)
(if (and (setq Reac
(car
(vl-remove-if-not
(function
(lambda (x)
(eq "TIMEREACT" (strcase (vlr-data x)))))
(mapcar (function cadr)
(vlr-reactors :vlr-command-reactor)))))
(vlr-added-p Reac))
(progn
(vlr-remove Reac)
(princ "\n<< Reactor Deactivated >>"))
   
(princ "\n** Reactor Not Running **"))
 
(princ))

Link to post
Share on other sites

Bill you are a rockstar !!! ... This is perfect is there any way to add a variable that will change the date daily ... so there would be a list of logs for the week so during that day it will write to the same file and then the next it would do the same to that days date ..

(if (setq ofile (open "C:\\Users\\Acad2015\\TimeLog\\Logfile-[color="red"][b]DATEVARIBLE[/b][/color].txt" "a"));;Location of change

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...