Create a new instance of MultiPurgeExample and then start it with Run.
C#
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
public class MultiPurgeExampleClass
{
private static int RunCount = 0;
private Autodesk.Revit.UI.UIApplication IntApp = null;
private Document IntDoc = null;
public void Run()
{
if (IntDoc == null)
return;
//Code upto this point your choice (part of IExternalCommand)
try
{
IntApp.DialogBoxShowing += ReturnOKResult;
}
catch (Exception ex)
{
}
RunCount = 0;
ReRun();
}
public MultiPurgeExampleClass(Autodesk.Revit.UI.ExternalCommandData CMD, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
IntApp = CMD.Application;
if (IntApp.ActiveUIDocument == null)
return;
IntDoc = IntApp.ActiveUIDocument.Document;
}
private void ReRun()
{
RunCount += 1;
Autodesk.Revit.UI.RevitCommandId CDMID = Autodesk.Revit.UI.RevitCommandId.LookupPostableCommandId(PostableCommand.PurgeUnused);
IntApp.PostCommand(CDMID);
}
private void ReturnOKResult(object s, Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs e)
{
e.OverrideResult(MsgBoxResult.Ok);
if (RunCount < 5)
{
ReRun();
}
else
{
RunCount = 0;
try
{
IntApp.DialogBoxShowing -= ReturnOKResult;
}
catch (Exception ex)
{
}
Interaction.MsgBox("Multi purge complete.", Title: "Information");
}
}
}