The dialog which provides the options of creating grids with selected lines/arcs
Inheritance: System.Windows.Forms.Form
コード例 #1
0
ファイル: Command.cs プロジェクト: AMEE/revit
        /// <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 virtual Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData
            , ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            try
            {
                Document document = commandData.Application.ActiveUIDocument.Document;

                // Get all selected lines and arcs
                CurveArray selectedCurves = GetSelectedCurves(commandData.Application.ActiveUIDocument.Document);

                // Show UI
                GridCreationOptionData gridCreationOption = new GridCreationOptionData(!selectedCurves.IsEmpty);
                using (GridCreationOptionForm gridCreationOptForm = new GridCreationOptionForm(gridCreationOption))
                {
                    DialogResult result = gridCreationOptForm.ShowDialog();
                    if (result == DialogResult.Cancel)
                    {
                        return Autodesk.Revit.UI.Result.Cancelled;
                    }

                    ArrayList labels = GetAllLabelsOfGrids(document);
                    DisplayUnitType dut = GetLengthUnitType(document);
                    switch (gridCreationOption.CreateGridsMode)
                    {
                        case CreateMode.Select: // Create grids with selected lines/arcs
                            CreateWithSelectedCurvesData data = new CreateWithSelectedCurvesData(commandData.Application, selectedCurves, labels);
                            using (CreateWithSelectedCurvesForm createWithSelected = new CreateWithSelectedCurvesForm(data))
                            {
                                result = createWithSelected.ShowDialog();
                                if (result == DialogResult.OK)
                                {
                                    // Create grids
                                    Transaction transaction = new Transaction(document, "CreateGridsWithSelectedCurves");
                                    transaction.Start();
                                    data.CreateGrids();
                                    transaction.Commit();
                                }
                            }
                            break;

                        case CreateMode.Orthogonal: // Create orthogonal grids
                            CreateOrthogonalGridsData orthogonalData = new CreateOrthogonalGridsData(commandData.Application, dut, labels);
                            using (CreateOrthogonalGridsForm orthogonalGridForm = new CreateOrthogonalGridsForm(orthogonalData))
                            {
                                result = orthogonalGridForm.ShowDialog();
                                if (result == DialogResult.OK)
                                {
                                    // Create grids
                                    Transaction transaction = new Transaction(document, "CreateOrthogonalGrids");
                                    transaction.Start();
                                    orthogonalData.CreateGrids();
                                    transaction.Commit();
                                }
                            }
                            break;

                        case CreateMode.RadialAndArc: // Create radial and arc grids
                            CreateRadialAndArcGridsData radArcData = new CreateRadialAndArcGridsData(commandData.Application, dut, labels);
                            using (CreateRadialAndArcGridsForm radArcForm = new CreateRadialAndArcGridsForm(radArcData))
                            {
                                result = radArcForm.ShowDialog();
                                if (result == DialogResult.OK)
                                {
                                    // Create grids
                                    Transaction transaction = new Transaction(document, "CreateRadialAndArcGrids");
                                    transaction.Start();
                                    radArcData.CreateGrids();
                                    transaction.Commit();
                                }
                            }
                            break;
                    }

                    if (result == DialogResult.OK)
                    {
                        return Autodesk.Revit.UI.Result.Succeeded;
                    }
                    else
                    {
                        return Autodesk.Revit.UI.Result.Cancelled;
                    }
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Autodesk.Revit.UI.Result.Failed;
            }
        }
コード例 #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 virtual Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData
                                                        , ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            try
            {
                Document document = commandData.Application.ActiveUIDocument.Document;

                // Get all selected lines and arcs
                CurveArray selectedCurves = GetSelectedCurves(commandData.Application.ActiveUIDocument.Document);

                // Show UI
                GridCreationOptionData gridCreationOption = new GridCreationOptionData(!selectedCurves.IsEmpty);
                using (GridCreationOptionForm gridCreationOptForm = new GridCreationOptionForm(gridCreationOption))
                {
                    DialogResult result = gridCreationOptForm.ShowDialog();
                    if (result == DialogResult.Cancel)
                    {
                        return(Autodesk.Revit.UI.Result.Cancelled);
                    }

                    ArrayList   labels = GetAllLabelsOfGrids(document);
                    ForgeTypeId unit   = GetLengthUnitType(document);
                    switch (gridCreationOption.CreateGridsMode)
                    {
                    case CreateMode.Select:     // Create grids with selected lines/arcs
                        CreateWithSelectedCurvesData data = new CreateWithSelectedCurvesData(commandData.Application, selectedCurves, labels);
                        using (CreateWithSelectedCurvesForm createWithSelected = new CreateWithSelectedCurvesForm(data))
                        {
                            result = createWithSelected.ShowDialog();
                            if (result == DialogResult.OK)
                            {
                                // Create grids
                                Transaction transaction = new Transaction(document, "CreateGridsWithSelectedCurves");
                                transaction.Start();
                                data.CreateGrids();
                                transaction.Commit();
                            }
                        }
                        break;

                    case CreateMode.Orthogonal:     // Create orthogonal grids
                        CreateOrthogonalGridsData orthogonalData = new CreateOrthogonalGridsData(commandData.Application, unit, labels);
                        using (CreateOrthogonalGridsForm orthogonalGridForm = new CreateOrthogonalGridsForm(orthogonalData))
                        {
                            result = orthogonalGridForm.ShowDialog();
                            if (result == DialogResult.OK)
                            {
                                // Create grids
                                Transaction transaction = new Transaction(document, "CreateOrthogonalGrids");
                                transaction.Start();
                                orthogonalData.CreateGrids();
                                transaction.Commit();
                            }
                        }
                        break;

                    case CreateMode.RadialAndArc:     // Create radial and arc grids
                        CreateRadialAndArcGridsData radArcData = new CreateRadialAndArcGridsData(commandData.Application, unit, labels);
                        using (CreateRadialAndArcGridsForm radArcForm = new CreateRadialAndArcGridsForm(radArcData))
                        {
                            result = radArcForm.ShowDialog();
                            if (result == DialogResult.OK)
                            {
                                // Create grids
                                Transaction transaction = new Transaction(document, "CreateRadialAndArcGrids");
                                transaction.Start();
                                radArcData.CreateGrids();
                                transaction.Commit();
                            }
                        }
                        break;
                    }

                    if (result == DialogResult.OK)
                    {
                        return(Autodesk.Revit.UI.Result.Succeeded);
                    }
                    else
                    {
                        return(Autodesk.Revit.UI.Result.Cancelled);
                    }
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
コード例 #3
0
        /// <summary>
        /// Run this sample now
        /// </summary>
        public void Run()
        {
            try
            {
                Document document = m_doc.Document;

                // Get all selected lines and arcs
                CurveArray selectedCurves = GetSelectedCurves(m_doc);

                // Show UI
                GridCreationOptionData gridCreationOption = new GridCreationOptionData(!selectedCurves.IsEmpty);
                using (GridCreationOptionForm gridCreationOptForm = new GridCreationOptionForm(gridCreationOption))
                {
                    DialogResult result = gridCreationOptForm.ShowDialog();
                    if (result == DialogResult.Cancel)
                    {
                        return;
                    }

                    ArrayList       labels = GetAllLabelsOfGrids(document);
                    DisplayUnitType dut    = GetLengthUnitType(document);
                    switch (gridCreationOption.CreateGridsMode)
                    {
                    case CreateMode.Select:     // Create grids with selected lines/arcs
                        CreateWithSelectedCurvesData data = new CreateWithSelectedCurvesData(m_doc, selectedCurves, labels);
                        using (CreateWithSelectedCurvesForm createWithSelected = new CreateWithSelectedCurvesForm(data))
                        {
                            result = createWithSelected.ShowDialog();
                            if (result == DialogResult.OK)
                            {
                                // Create grids
                                data.CreateGrids();
                            }
                        }
                        break;

                    case CreateMode.Orthogonal:     // Create orthogonal grids
                        CreateOrthogonalGridsData orthogonalData = new CreateOrthogonalGridsData(m_doc, dut, labels);
                        using (CreateOrthogonalGridsForm orthogonalGridForm = new CreateOrthogonalGridsForm(orthogonalData))
                        {
                            result = orthogonalGridForm.ShowDialog();
                            if (result == DialogResult.OK)
                            {
                                // Create grids
                                orthogonalData.CreateGrids();
                            }
                        }
                        break;

                    case CreateMode.RadialAndArc:     // Create radial and arc grids
                        CreateRadialAndArcGridsData radArcData = new CreateRadialAndArcGridsData(m_doc, dut, labels);
                        using (CreateRadialAndArcGridsForm radArcForm = new CreateRadialAndArcGridsForm(radArcData))
                        {
                            result = radArcForm.ShowDialog();
                            if (result == DialogResult.OK)
                            {
                                // Create grids
                                radArcData.CreateGrids();
                            }
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }