Idling&ExternalEvent

Idling Event

  • Idling event refers to executing commands when revit has no operation
  • TheBuildingCoder explanation
  • code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

public static void IdlingHandler(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs args)
{
UIApplication uiapp = sender as UIApplication;
if (uiapp != null)
{
Autodesk.Revit.UI.UIDocument uidoc = uiapp.ActiveUIDocument;
Autodesk.Revit.DB.Document doc = uidoc.Document;
if (uidoc != null && doc != null)
{
Reference re = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "");
Element e = doc.GetElement(re);

UserControl1.mainPage.Label1.Content = e.Id.ToString() + "\r";
uiapp.Idling -= IdlingHandler;
}
}
else
{
System.Windows.Forms.MessageBox.Show("Must should Idling!");
}
}
  • TIPS: It is best to append uninstall event after mounting event, otherwise event will not stop and will repeat operation in idling all the time :smile_cat:

External Event

  • External event refers to event used when calling revit command in form or externally
  • Need to reference interface: IexternalEventHandler
  • code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class ExternalHandler : IExternalEventHandler
{
public void Execute(UIApplication app)
{

ThisApplication.thisApp.AddIdlingEvent(app);

}

public string GetName()
{
return "ExternalHander.Excute()";
}
}