public Result OnStartup(UIControlledApplication application)
{
_cachedUiCtrApp.Idling += OnIdling;
}
private void OnIdling(object sender, IdlingEventArgs e)
{
_cachedUiCtrApp.Idling -= OnIdling;
UIApplication uiApp = sender as UIApplication;
try
{
var filename = siemensRevitFIleListLogFilePath;
if (System.IO.File.Exists(filename))
{
string logContent = System.IO.File.ReadAllText(filename);
System.IO.File.WriteAllText(filename, string.Empty);
string[] logLines = logContent.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
ProcessDocuments(uiApp, logLines);
}
}
catch (Exception ex)
{
LogException(ex, "Error in OnIdling method");
}
}
private void ProcessDocuments(UIApplication uiApp, string[] filePaths)
{
foreach (var filePath in filePaths)
{
Document previousDoc = null;
try
{
UIDocument uiDocument = uiApp.OpenAndActivateDocument(filePath);
Document currentDoc = uiApp.ActiveUIDocument.Document;
if (currentDoc != null && currentDoc.IsValidObject)
{
RunExportProcess(currentDoc);
}
previousDoc = currentDoc;
}
catch (Exception ex)
{
MessageBox.Show(ex + "");
LogException(ex, $"Error processing file {filePath}");
}
}
}