/// <summary> /// Form closed event handler /// </summary> /// <param name="e"></param> protected override void OnFormClosed(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); }
/// <summary> /// This method creates and shows a modeless dialog, unless it already exists. /// </summary> /// <remarks> /// The external command invokes this on the end-user's request /// </remarks> /// public void ShowForm_RotatingForm(UIApplication uiapp) { // If we don't have dialog yet, create and show it if (m_rotatingForm == null || m_rotatingForm.IsDisposed) { // A new handler handle request posting by the dialog RotateMultiExternalEvent handler = new RotateMultiExternalEvent(); // External event for the dialog to use (to post request) ExternalEvent exEvent = ExternalEvent.Create(handler); // We give the objects to the new dialog; // The dialog becomes the owner responsible fore disposing them, eventually. m_rotatingForm = new Rotating_Form(exEvent, handler); m_rotatingForm.Show(); } }
/// <summary> /// The top method of the event handler. /// </summary> /// <remarks> /// This is called by Revit after the corresponding /// external event was raised (by the modeless form) /// and Revit reached the time at which it could call /// the event's handler (i.e. this object) /// </remarks> /// public void Execute(UIApplication app) { UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; RotateMultiExternalEvent rotateMultiExternalEvent = new RotateMultiExternalEvent(); ExternalEvent exEvent = ExternalEvent.Create(rotateMultiExternalEvent); Rotating_Form rotating_Form = new Rotating_Form(exEvent, rotateMultiExternalEvent); try { using (Transaction t = new Transaction(doc)) { try { //Provide access to make change in document t.Start("Rotate Elements"); // Collect selected elements ICollection <ElementId> selectedElements = uidoc.Selection.GetElementIds(); RotateMethod(doc, selectedElements, App.angleX, App.angleY, App.angleZ); t.Commit(); App.thisApp.WakeFormUp_RotatingForm(); } catch (Exception e) { TaskDialog.Show("ERROR", e.Message + "\n" + e.Source); } } } finally { App.thisApp.WakeFormUp_RotatingForm(); } return; }
/// <summary> /// Rotating form constructor /// </summary> /// <param name="exEvent">External event which implemented when raise calling</param> /// <param name="handler">Revit API Externl Event Handler</param> public Rotating_Form(ExternalEvent exEvent, RotateMultiExternalEvent handler) { InitializeComponent(); m_Handler = handler; m_ExEvent = exEvent; }