Idling&ExternalEvent 空闲事件与外部事件
空闲事件
空闲事件是指在revit无操作时执行命令TheBuildingCoder解释code
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:在挂载事件后最好后缀卸载事件,不然事件不会停止将一直重复idling里面的操作😸
外部事件
外部事件是指在窗体或外部调用revit命令时使用的事件需要引用接口:IexternalEventHandlercode
public class ExternalHandler : IExternalEventHandler
{
public void Execute(UIApplication app)
{
ThisApplication.thisApp.AddIdlingEvent(app);
}
public string GetName()
{
return "ExternalHander.Excute()";
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-27485.html