Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: poppabear on June 26, 2008, 04:40:30 PM

Title: Here is a TRUE part Elapsed time, date file creator macros
Post by: poppabear on June 26, 2008, 04:40:30 PM
Ok, here is a solution,  It doesnt take into account of changing from the last day of one month, and the start of another.
Also, the same for Year Changes, it only takes into account Consecutive days in the same month.
Also The "CostEstimate.txt" File, will create itself in the Mach3 main directory.
If you want it to create some where else, you will need to change the path to where you want it to drop.
NOTE: The intermediate file "Time File" will create and destroy itself with the complete running of the G-Code part file.
What this does is create a file, called: "CostEstimate.txt"  This text shows Start Time and Date, End Time and Date, and total elapsed time on that part for: Days, Hours, Minutes, Seconds
This is TRUE elapsed time while on that part, so if you pause your G-Code for 1 hour then come back and hit cycle start, then it will add that hour to the program.

Things you will have to do for Setup:
1). You will have to change your computers System time to 24 hour clock for the time calculation to work.
2). You will need to put the Macro "M1002" at least one line down from the start of your code, and before your part starts. (the line above it can be a comment), or Init G codes.
3). You will need to put the Macro "M1003" right before your last line, which should be a M30.

Other Things:
1). You will need to run the file completly from start to finish, since these to Macros are linked to create and destroy it intermediates.
2). Once you run a part, you will have to Copy and MOVE that file, out of that area, and Print it off, If you run that same part, or some other part, the next run will delete that file, and recreate it at the end, with the new times from start to finish.

Here is the Start Timer, Date, Macro: M1002.m1s

'****************************
'M1002.m1s  Store Start time point

Open "CostEstimate.txt" For Output As #2
Close #2

Kill "CostEstimate.txt"

Dim StartTime As String               
Dim StartDate As String               

StartTime = Time(Now)
StartDate = Date()

Open "TimeFile" For Output As #1   ' Open to write file.
Write #1, StartTime
Write #1, StartDate
Close #1

Code "G4 P0.5"
While IsMoving
Wend

Sec = Second(StartTime)
Min = Minute(StartTime)
Hr = Hour(StartTime)
Dy = Day(StartDate)

SetVar(100,Sec)
SetVar(101,Min)
SetVar(102,Hr)
SetVar(103,Dy)
'***************************** 

Here is the End Timer, Date, Macro: M1003.m1s

 '*****************************
'M1003.m1s  Get End Time point and calc, and post file

Dim StartTime As String
Dim StartDate As String
Dim EndTime As String
Dim EndDate As String
Dim File As String
Dim Days

EndTime = Time(Now)
EndDate = Date()
SecEnd = Second(EndTime)
MinEnd = Minute(EndTime)
HrEnd = Hour(EndTime)
DyEnd = Day(EndDate)

SecStart = GetVar(100)
MinStart = GetVar(101)
HrStart = GetVar(102)
DyStart = GetVar(103)

File = FileName()

Open "TimeFile" For Input As #1   ' Open file.   
   Line Input #1, TextLine      ' Read line into variable.
   StartTime = TextLine      ' get start time.
   Line Input #1, TextLine      ' Read line into variable.
   StartDate = TextLine      ' get start date.   
Close #1                  ' Close file.

Code "G4 P0.5"
While IsMoving
Wend

If HrEnd<HrStart Then
Hr=((24-HrStart)+(24-(24-HrEnd)))
Else
Hr=(HrEnd-HrStart)
End If

If MinEnd<MinStart Then
Min=((60-MinStart)+(60-(60-MinEnd)))
Else
Min=(MinEnd-MinStart)
End If

If SecEnd<SecStart Then
Sec=((60-SecStart)+(60-(60-SecEnd)))
Else
Sec=(SecEnd-SecStart)
End If

If (DyEnd-DyStart)= 0 Then
Days = 0
End If

If ((DyEnd-DyStart)=1) And (HrEnd<HrStart) Then
Days = 0
End If

If ((DyEnd-DyStart)=1) And (HrEnd>HrStart) Then
Days = 1
End If

If ((DyEnd-DyStart)>1) Then
Days = (DyEnd-DyStart)
End If

Kill "TimeFile"

Open "CostEstimate.txt" For Output As #2   ' Open to write file.
Write #2, "File Name: " & File
Write #2, "Start Time: " & StartTime, "Start Date: " & StartDate
Write #2, "End Time: " & EndTime, "End Date: " & EndDate
Write #2, "Total Time: " & " Days: " & Days & " Hours: " & Hr & " Mins: " & Min & " Secs: " & Sec
Close #2

Code "G4 P0.5"
While IsMoving
Wend
'*******************************************

'Hope this helps you
'Scott
Title: Re: Here is a TRUE part Elapsed time, date file creator macros
Post by: Chaoticone on June 26, 2008, 06:13:50 PM
Thanks for shareing that with us Scott.

Brett
Title: Re: Here is a TRUE part Elapsed time, date file creator macros
Post by: vmax549 on July 01, 2008, 10:09:49 AM
GOOD Job Scott, I have a project for YA. We could use a utility to see a LCAM project file AND print out a summary of the file. THings such as NAME,TOOL list, date, time to cut,etc,etc

(;-)TP
Title: Re: Here is a TRUE part Elapsed time, date file creator macros
Post by: vmax549 on July 01, 2008, 11:22:26 AM
Sorry Scott, I am just on here to help the HOBBY macherteers where I can. BUT then again I don't have to make a living at it.

Good Luck,

(;-) TP
Title: Re: Here is a TRUE part Elapsed time, date file creator macros
Post by: penmaker1 on March 08, 2009, 08:42:44 AM
Hi Scott,

This works very well, I made a couple of minor changes to get what I need.  It now keeps appending to the CostEstimate file and I changed the output format to be more useable with Excel or some other spread sheet.  Now I just need to add the M1002 and M1003 macro calls to my TurboCADCAM configuration so that they are automatically added to each part file. 

Thank you for making the macros available.

John Guenther
'Ye Olde Pen Maker'
Sterling, Virginia
Title: Re: Here is a TRUE part Elapsed time, date file creator macros
Post by: penmaker1 on March 12, 2009, 04:00:56 PM
I took the macro's posted by Scott and modified them slightly to produce a running job log.  The output file is compatible with Microsoft Excel.  I did this becuase I need to be able to track total time for a job with multiple parts in varying quantities for each part.

It still works Scott originally posted it with the exception that the resulting output from the M1003 macro is not destroyed with each run.

'****************************
'M1002.m1s  Store Start time point

Dim StartTime As String               
Dim StartDate As String               

StartTime = Time(Now)
StartDate = Date()

Open "TimeFile" For Output As #1   ' Open to write file.
Write #1, StartTime
Write #1, StartDate
Close #1

Code "G4 P0.5"
While IsMoving
Wend

Sec = Second(StartTime)
Min = Minute(StartTime)
Hr = Hour(StartTime)
Dy = Day(StartDate)

SetVar(100,Sec)
SetVar(101,Min)
SetVar(102,Hr)
SetVar(103,Dy)
'***************************** 

Here is the M1003 macro:

'*****************************
'M1003.m1s  Get End Time point and calc, and post file

Dim StartTime As String
Dim StartDate As String
Dim EndTime As String
Dim EndDate As String
Dim File As String
Dim Days

EndTime = Time(Now)
EndDate = Date()
SecEnd = Second(EndTime)
MinEnd = Minute(EndTime)
HrEnd = Hour(EndTime)
DyEnd = Day(EndDate)

SecStart = GetVar(100)
MinStart = GetVar(101)
HrStart = GetVar(102)
DyStart = GetVar(103)

File = FileName()

Open "TimeFile" For Input As #1   ' Open file.   
   Line Input #1, TextLine      ' Read line into variable.
   StartTime = TextLine      ' get start time.
   Line Input #1, TextLine      ' Read line into variable.
   StartDate = TextLine      ' get start date.   
Close #1                  ' Close file.

Code "G4 P0.5"
While IsMoving
Wend

If HrEnd<HrStart Then
   Hr=((24-HrStart)+(24-(24-HrEnd)))
ElseIf (HrEnd>HrStart and MinEnd>MinStart) Then
   Hr=(HrEnd-HrStart)
Else
   Hr = 0
End If

If MinEnd<MinStart Then
   Min=((60-MinStart)+(60-(60-MinEnd)))
ElseIf (MinEnd>MinStart And SecEnd>SecStart) Then
   Min=(MinEnd-MinStart)-1
Else
   Min=(MinEnd-MinStart)   
End If

If SecEnd<SecStart Then
Sec=((60-SecStart)+(60-(60-SecEnd)))
Else
Sec=(SecEnd-SecStart)
End If

If (DyEnd-DyStart)= 0 Then
Days = 0
End If

If ((DyEnd-DyStart)=1) And (HrEnd<HrStart) Then
Days = 0
End If

If ((DyEnd-DyStart)=1) And (HrEnd>HrStart) Then
Days = 1
End If

If ((DyEnd-DyStart)>1) Then
Days = (DyEnd-DyStart)
End If

Kill "TimeFile"

Open "CostEstimate.csv" For Append As #2   ' Open to write file.
Write #2, File & " " & "," & StartDate & "," & StartTime & "," & EndDate & "," & EndTime & ","& Days & "," & Hr & ":" & Min & ":" & Sec
Close #2

Code "G4 P0.5"
While IsMoving
Wend

'*****************************

The only thing I am not pleased with is the CostEstimate.csv file has some double quotation marks in it that can be a problem for Excel to deal with.  I would also like to be able to get rid of the AM and PM designations on the two time fields but have not been able to determine if VBscript will allow me to do that.  Some or all of these problems are either due to the Cypress Enable scripting package or to my lack of knowledge in this area.

Any help or comments will be welcomed.

John Guenther
'Ye Olde Pen Maker'
Sterling, Virginia
Title: Re: Here is a TRUE part Elapsed time, date file creator macros
Post by: poppabear on March 12, 2009, 06:36:56 PM
You will need to set your System Clock to 24 hour mode instead of 12 hour mode to eliminate the AM/PM thing.

ON the "" thing, I dont know why your getting them in the CVS file, since you are not setting them in your write file.

You can try to reformat your write like this:

Write #2, File
Write #2, StartDate
Write #2, StartTime
Write #2, EndDate
Write #2, EndTime
Write #2, Days
Write #2, Hr & ":" & Min & ":" & Sec

scott
Title: Re: Here is a TRUE part Elapsed time, date file creator macros
Post by: rweatherly on March 15, 2009, 09:46:25 AM
If you want to keep AM and PM on you computer clock, you can eliminate them in the write file by:

a = InStr(StartTime, " ")  'finds the first space in StartTime, which will be just before the AM or PM
StartTime = Mid$(StartTime, 1, a - 1)   'truncates the StartTime string to just before the space

Richard
Title: Re: Here is a TRUE part Elapsed time, date file creator macros
Post by: penmaker1 on March 15, 2009, 11:38:02 AM
Thanks Richard,

I found a timediff function posted somewhere in the internet that I have incorporated in the M1003 macro, I am now getting what I need from the macro and I have the format coming out like I want it to.

I will be posting the revised macro later today.  I ran 72 parts o the lathe Friday and yesterday with the macros running and got the output I needed.  I will be running some more on the lathe and mill today, once I am satisfied with the output I will update my original post with the corrected versions of the macros.  I still have not figured out how to stop it from enclosing the entire output line in quotes but I can live with that.

Thanks to everyone who replied and made suggestions, they were appreciated.

John Guenther
'Ye Olde Pen Maker'
Sterling, Virginia

Title: Re: Here is a TRUE part Elapsed time, date file creator macros
Post by: rweatherly on March 15, 2009, 12:16:59 PM
If I change the Write #1 to Print #1, it eliminates the first and last quotes.

There are still quotes on the start  date and time for some reason.

Richard
Title: Re: Here is a TRUE part Elapsed time, date file creator macros
Post by: penmaker1 on March 15, 2009, 12:38:03 PM
Richard,

Thanks, that is great news.  I did figure out how to get rid of the quotes on start date and time using the mid function.

   StartTime = Mid(TextLine,2,8) ' get start time.

   StartDate = Mid(TextLine,2,10) ' get start date.   

worked for me.

Thanks again,

John Guenther
'Ye Olde Pen Maker'
Sterling, Virginia
Title: Re: Here is a TRUE part Elapsed time, date file creator macros
Post by: rweatherly on March 15, 2009, 01:34:04 PM
You may have to check the length of the string, since there are not always a constant number of characters...

Like 03/09/2009 vs. 3/9/2009