Cool thread. Even though this is LISP thread I thought I might share my experiences with VBA in creating a time tracker.
I created VB(A) routines for AutoCAD, Word, Excel, Outlook, Access, and photoshop scripts that report back to a MS Access database. I haven't worked much in revit but I will tackle that when I work with it more.
At the end of the week I just create a report (from a premade template) that shows exactly what I did within the given time frame. It has graphs, pie charts, and totals showing time spent on different projects within the given time frame. The program figures out the project number from where the files reside on the network. For emails for example, I always put our project number first thing in the subject line so it gets parsed correctly, and the database stores the body of the text in a text field. It do all the calculations, sorting, graphing, etc within the MS Access client, and all the VBA or scripting routines do is report the data to the database. I've been using it for over 1 year now flawlessly, the database file has over 70,000 records and is only 20MB.
Here is the AutoCAD part of the VBA code:
Code:
'~~~~This Drawing module~~~~
Private Sub AcadDocument_Activate()
Call makeRecord("Activated")
End Sub
Private Sub AcadDocument_BeginClose()
Call makeRecord("Close")
End Sub
Private Sub AcadDocument_BeginDocClose(Cancel As Boolean)
Call makeRecord("DocClose")
End Sub
Private Sub AcadDocument_Deactivate()
Call makeRecord("Deactivated")
End Sub
Private Sub AcadDocument_EndPlot(ByVal DrawingName As String)
Call makeRecord("Plot")
End Sub
Private Sub AcadDocument_EndSave(ByVal FileName As String)
Call makeRecord("Save")
End Sub
Private Sub AcadDocument_LayoutSwitched(ByVal LayoutName As String)
Call makeRecord("Changed Layout to " & LayoutName)
End Sub
Code:
'~~~~module code~~~~
'requires DAO reference
Private Const LocOfDB As String = "\My Documents\Time Tracker\TimeTracking.mdb"
Public Sub makeRecord(evType As String)
On Error Resume Next
Dim uName As String, dbPath As String
Dim dbThisDB As DAO.Database
Dim rcdCID As DAO.Recordset
uName = Environ("USERNAME")
dbPath = Environ("USERPROFILE") + LocOfDB
Set dbThisDB = OpenDatabase(dbPath)
Set rcdCID = dbThisDB.OpenRecordset("tblAcadLog")
rcdCID.AddNew
rcdCID![DateOfEntry] = Now()
rcdCID![TypeOfApp] = "AutoCAD"
rcdCID![EventType] = evType
rcdCID![FileName] = Application.ActiveDocument.Name
rcdCID![FileDirectory] = Application.ActiveDocument.Path
rcdCID![ProjectNumber] = findPN(Application.ActiveDocument.Path)
rcdCID![UserName] = uName
'rcdCID![FileLastSave] = Application.ActiveDocument.GetVariable("TDUPDATE")
rcdCID![FileLastSave] = Format(Application.ActiveDocument.GetVariable("TDUPDATE"), Date) & " " & _
Format(Application.ActiveDocument.GetVariable("TDUPDATE"), "hh:mm:ss AMPM")
rcdCID![FileElapsedTime] = Application.ActiveDocument.GetVariable("TDINDWG")
rcdCID![SessionElapsedTime] = Application.ActiveDocument.GetVariable("TDUSRTIMER")
rcdCID.Update
rcdCID.Close
Set rcdCID = Nothing
Set dbThisDB = Nothing
End Sub
Function findPN(inputStr)
If InStr(1, inputStr, "Projects\") > 0 Then
fixstr = Replace(Trim(Mid(inputStr, InStr(1, inputStr, "rojects\") + 13)), " ", " ")
fixstr = Trim(Left(fixstr, InStr(1, fixstr, "\")))
If InStr(1, fixstr, " ") > 0 Then
fixstr = Trim(Left(fixstr, InStr(1, fixstr, " ")))
End If
findPN = Trim(Replace(fixstr, "\", ""))
Else
findPN = "Unknown"
End If
End Function