/// <summary>
 /// Symbol Selection Form Class Instance and Initializer
 /// </summary>
 /// <param name="exEvent">External event which implemented when raise calling</param>
 /// <param name="handler">Revit API Externl Event Handler</param>
 /// <param name="m_doc">Active Revit Document</param>
 public SymbolSelectionForm(ExternalEvent exEvent, CreateBeamExternalEventHandler handler, Document m_doc)
 {
     InitializeComponent();
     m_Handler = handler;
     m_ExEvent = exEvent;
     doc       = m_doc;
 }
Beispiel #2
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            Document doc = commandData.Application.ActiveUIDocument.Document;

            try
            {
                ArrayList beamMap = new ArrayList();
                CreateBeamExternalEventHandler.beamSymbols(doc, beamMap);
                App.beamMaps = beamMap;

                ArrayList connectionTypeMap = new ArrayList();
                SteelUtilities.structuralConnectionTypeArray(doc, connectionTypeMap);
                App.structuralConnectionMap = connectionTypeMap;

                App.thisApp.ShowForm_SymbolSelection(commandData.Application);

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
        /// <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);
        }
Beispiel #4
0
        /// <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_SymbolSelection(UIApplication uiapp)
        {
            // If we don't have dialog yet, create and show it
            if (m_SymbolSelection == null || m_SymbolSelection.IsDisposed)
            {
                // A new handler handle request posting by the dialog
                CreateBeamExternalEventHandler handler = new CreateBeamExternalEventHandler();

                // 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_SymbolSelection = new SymbolSelectionForm(exEvent, handler, uiapp.ActiveUIDocument.Document);
                m_SymbolSelection.Show();
            }
        }
Beispiel #5
0
        /// <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>
        /// <param name="app">Revit User Interface Application</param>
        public void Execute(UIApplication app)
        {
            UIDocument uidoc = app.ActiveUIDocument;
            Document   doc   = uidoc.Document;
            View       view  = doc.ActiveView;

            // External Event Handler Instance
            CreateBeamExternalEventHandler createBeamExternalEventHandler = new CreateBeamExternalEventHandler();
            // Create a external event inherited from handler.
            ExternalEvent externalEvent = ExternalEvent.Create(createBeamExternalEventHandler);

            // Modeless Form Instance
            SymbolSelectionForm symbolSelectionForm = new SymbolSelectionForm(externalEvent, createBeamExternalEventHandler, doc);

            try
            {
                using (Transaction t = new Transaction(doc))
                {
                    //Provide access to make change in document
                    t.Start("Create Beam W Columns");

                    // Collect selected objects element id
                    ICollection <ElementId> selElements = uidoc.Selection.GetElementIds();

                    ICollection <ElementId> structuralColumns =
                        new FilteredElementCollector(uidoc.Document, selElements).OfCategory(BuiltInCategory.OST_StructuralColumns).ToElementIds();

                    CreateBeamMethod(doc, view, structuralColumns, symbolSelectionForm);

                    t.Commit();
                    App.thisApp.WakeFormUp_SymbolSelectionForm();
                }
            }
            catch (Exception e)
            {
                TaskDialog.Show("INFO", e.Message);
            }
            finally
            {
                App.thisApp.WakeFormUp_SymbolSelectionForm();
            }
            return;
        }