Hey Anton are you a Kiwi? Are you friends with the Kiwi codes developers, I used to work at Meteir 3 in Melbourne with one of them. Anyway I used the following code below. This is not ideal and was just meant as a temporary solution as the output is to an delimited file that i visualize in powerbi. Ideally you would send to a database and could then leverage the data elsewhere.
public void OnDocClosing(object sender, DocumentClosingEventArgs e)
{
try
{
//saves to a tab delimiter to .csv
RecordAddinData.WhatExternalCommandWasExecuted(e.Document, MySQLDateTimeConverter(DateTime.Now));
}
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Analysis;
using System;
using System.Collections.Generic;
using System.IO;
namespace TechnoCore
{
internal static class RecordAddinData
{
internal static List<string> WhatExternalCommandWasExecuted(Document doc, DateTime dateTimeClosing)
{
List<string> commandsExecuted = new List<string>();
try
{
string userName = GetThreeInitials(doc);
bool isFamilyDoc = doc.IsFamilyDocument;
string projType;
string projStatus;
if (isFamilyDoc)
{
projType = "NULL";
projStatus = "NULL";
}
else
{
EnergyDataSettings energyDataSetting = EnergyDataSettings.GetFromDocument(doc);
projType = energyDataSetting.BuildingType.ToString();
ProjectInfo m_info = doc.ProjectInformation;
projStatus = !string.IsNullOrWhiteSpace(m_info.Status) ? m_info.Status : null;
}
string journalPath = doc.Application.RecordingJournalFilename;
List<string> JournalLines = new List<string>();
string searchString = "Jrn.RibbonEvent \"Execute external command:";
var fs = new FileStream(journalPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using (var sr = new StreamReader(fs))
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (line.Contains(searchString))
{
int pFrom = line.IndexOf(":PT_") + ":PT_".Length;
int pTo = line.LastIndexOf("\"");
string result = line.Substring(pFrom, pTo - pFrom);
if (line.ToUpperInvariant().Contains("DLM INTEGRATOR")) { result = "Delslack.Infiltrator";}
else if (line.ToUpperInvariant().Contains("UPREV")) { result = "Xrev.Uprev"; }
else if (line.ToUpperInvariant().Contains("REVIT LOOKUP")) { result = "Inspector.RevitLookup"; }
commandsExecuted.Add(
userName + "\t" +
result + "\t" +
projType + "\t" +
projStatus + "\t" +
dateTimeClosing + "\t" +
doc.IsFamilyDocument.ToString()
);
}
}
}
AppendTextLinesToNotepad(commandsExecuted, PATHS.ADDINS_SVR(doc, @"External-Command-Usage.csv"));
}
catch (Exception) { }
return commandsExecuted;
}
internal static string GetThreeInitials(Document _doc)
{
string userName = _doc.Application.Username.ToUpperInvariant().Replace(".", "");
switch (userName.Length)
{
case 0:
return "XYZ";
case 1:
return userName + "YZ";
case 2:
return userName + "Z";
default:
return userName.Substring(0, 3);
}
}
private static void AppendTextLinesToNotepad(List<string> list, string filename)
{
using (StreamWriter outputFile = new StreamWriter(filename, true))
{
foreach (string item in list)
{
outputFile.WriteLine(item);
}
}
}
}//cl
}//ns