'#Reference {420B2830-E718-11CF-893D-00A0C9054228}#1.0#0#C:\WINDOWS\System32\scrrun.dll#Microsoft Scripting Runtime Option Explicit ' revised 3/1/2004: changed all of the integers to longs to allow for an editting time ' that exceeds 32767 seconds, which is about 9 hours Dim dic As Dictionary Public Sub AddIn_OnConnect(ByVal flags As FeatureCAM.tagFMAddInFlags) Set dic = New Dictionary End Sub Public Sub Application_DocumentBeforeSave(doc As FeatureCAM.FMDocument, ByVal SaveAsUI As Boolean, Cancel As Boolean) If dic.Exists( fixTheName( doc ) ) Then Dim documentOpenedAt As Double Dim rightNow As Date Dim totalSessionTime As Long documentOpenedAt = dic.Item( fixTheName( doc ) ) rightNow = Now totalSessionTime = DateDiff( "s", documentOpenedAt, rightNow ) dic.Remove( fixTheName( doc ) ) Dim runningTotal As Long Dim newRunningTotal As Long runningTotal = doc.UserAttribute( "RunningTotalEditingTime" ) newRunningTotal = runningTotal + totalSessionTime Dim OldMins As Long Dim OldSecs As Long Dim NewMins As Long Dim NewSecs As Long OldMins = Int( runningTotal / 60 ) OldSecs = runningTotal - (OldMins * 60) NewMins = Int( newRunningTotal / 60 ) NewSecs = newRunningTotal - (NewMins * 60) MsgBox "Previous editting time was " & OldMins & _ "m and " & OldSecs & "s, this session was " & totalSessionTime & _ "s, for a total of " & NewMins & "m and " & NewSecs & "s." doc.SetUserAttribute( "RunningTotalEditingTime", newRunningTotal ) Else MsgBox( "I have no record of when " & _ fixTheName( doc ) & " was opened and cannot report the time." ) End If SetTheTimeInDictionary( doc ) End Sub Public Sub Application_DocumentNew(Doc As FeatureCAM.FMDocument) SetTheTimeInDictionary( Doc ) End Sub Public Sub Application_DocumentOpen(Doc As FeatureCAM.FMDocument) Dim runningTotal As Long runningTotal = Doc.UserAttribute( "RunningTotalEditingTime" ) If runningTotal > 0 Then Dim mins As Long Dim secs As Long mins = Int( runningTotal / 60 ) secs = runningTotal - (mins * 60) MsgBox "This document has a total editing time of " & mins & "m and " & secs & "s." End If SetTheTimeInDictionary( Doc ) End Sub Private Sub SetTheTimeInDictionary( Doc As FeatureCAM.FMDocument ) Dim rightNow As Date rightNow = Now Dim r As Double r = rightNow If dic.Exists( fixTheName( Doc ) ) Then dic.Remove( fixTheName( Doc ) ) End If dic.Add( fixTheName( Doc ), r ) End Sub Private Function fixTheName( Doc As FeatureCAM.FMDocument ) If Not LCase( Right( Doc.Name , 3 ) ) = ".fm" Then If TypeName( Doc ) = "IFMDocument" Then fixTheName = Doc.Name + ".fm" Else ' we don't know how to fix the name for mf or tsf documents fixTheName = Doc.Name End If Else fixTheName = doc.Name End If End Function