public Result OnShutdown(UIControlledApplication application) { if (m_MyForm != null && m_MyForm.Visible) { m_MyForm.Close(); }
return Result.Succeeded; }
public Result OnStartup(UIControlledApplication application) { m_MyForm = null; // no dialog needed yet; the command will bring it thisApp = this; // static access to this application instance
return Result.Succeeded; }
// The external command invokes this on the end-user's request publicvoidShowForm(UIApplication uiapp) { // If we do not have a dialog yet, create and show it if (m_MyForm == null || m_MyForm.IsDisposed) { // A new handler to handle request posting by the dialog ExternalEventExample handler = new ExternalEventExample();
// External Event for the dialog to use (to post requests) ExternalEvent exEvent = ExternalEvent.Create(handler);
// We give the objects to the new dialog; // The dialog becomes the owner responsible for disposing them, eventually. m_MyForm = new ExternalEventExampleDialog(exEvent, handler); m_MyForm.Show(); } } }
protectedoverridevoidOnFormClosed(FormClosedEventArgs e) { // we own both the event and the handler // we should dispose it before we are closed m_ExEvent.Dispose(); m_ExEvent = null; m_Handler = null;
// do not forget to call the base class base.OnFormClosed(e); }
调用ExternalEvent.Raise()方法时,Revit将等待可用的Idling计时器,然后调用IExternalEventEvent.Execute()方法。在这个简单的例子中,它将显示一个TaskDialog,文本为“Click Close to close.”“,如上面第一个代码区域所示。