Summary description for PutDialog.
Inheritance: System.Windows.Forms.Form
        /// <summary>
        /// Run this sample
        /// </summary>
        public void Run()
        {
            RotateFramingObjectsForm displayForm = new RotateFramingObjectsForm(this);
            ElementSet selection = new ElementSet();
            ICollection <ElementId> sel;

            foreach (ElementId elementid in m_doc.Selection.GetElementIds())
            {
                selection.Insert(m_doc.Document.GetElement(elementid));
            }

            bool isSingle            = true;              //selection is single object
            bool isAllFamilyInstance = true;              //all is not familyInstance

            // There must be beams, braces or columns selected
            if (selection.IsEmpty)
            {
                // nothing selected
                MessageBox.Show("Please select FamilyInstance.(such as column)", "RotateFramingObjects");
                return;
            }
            else if (1 != selection.Size)
            {
                isSingle = false;
                try
                {
                    if (DialogResult.OK != displayForm.ShowDialog())
                    {
                        return;
                    }
                }
                catch (Exception)
                {
                    return;
                }
                //	return IExternalCommand.Result.Succeeded;
                // more that one object selected
            }

            // if the selection are familyInstance, try to get their existing rotation
            foreach (Autodesk.Revit.DB.Element e in selection)
            {
                FamilyInstance familyComponent = e as FamilyInstance;
                if (familyComponent != null)
                {
                    if (Autodesk.Revit.DB.Structure.StructuralType.Beam == familyComponent.StructuralType ||
                        Autodesk.Revit.DB.Structure.StructuralType.Brace == familyComponent.StructuralType)
                    {
                        // selection is a beam or brace
                        string returnValue = this.FindParameter("Angle", familyComponent);
                        displayForm.rotationTextBox.Text = returnValue.ToString();
                    }
                    else if (Autodesk.Revit.DB.Structure.StructuralType.Column == familyComponent.StructuralType)
                    {
                        // selection is a column
                        Autodesk.Revit.DB.Location      columnLocation = familyComponent.Location;
                        Autodesk.Revit.DB.LocationPoint pointLocation  = columnLocation as Autodesk.Revit.DB.LocationPoint;
                        double temp   = pointLocation.Rotation;
                        string output = (Math.Round(temp * 180 / (Math.PI), 3)).ToString();
                        displayForm.rotationTextBox.Text = output;
                    }
                    else
                    {
                        // other familyInstance can not be rotated
                        MessageBox.Show("Can not deal with it.", "RotateFramingObjects");
                        sel = m_doc.Selection.GetElementIds();
                        sel.Add(familyComponent.Id);
                        m_doc.Selection.SetElementIds(sel);
                        return;
                    }
                }
                else
                {
                    if (isSingle)
                    {
                        MessageBox.Show("It is a Non-FamilyInstance.", "RotateFramingObjects");
                        sel = m_doc.Selection.GetElementIds();
                        sel.Add(e.Id);
                        m_doc.Selection.SetElementIds(sel);
                        return;
                    }
                    // there is some objects is not familyInstance
                    //MessageBox.Show("There is Non-FamilyInstance.", "RotateFramingObjects");
                    sel = m_doc.Selection.GetElementIds();
                    sel.Add(e.Id);
                    m_doc.Selection.SetElementIds(sel);
                    isAllFamilyInstance = false;
                }
            }


            if (isSingle)
            {
                try
                {
                    if (DialogResult.OK != displayForm.ShowDialog())
                    {
                        return;
                    }
                }
                catch (Exception)
                {
                    return;
                }
            }

            if (isAllFamilyInstance)
            {
                return;
            }
            else
            {
                //output error information
                return;
            }
        }
Ejemplo n.º 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 Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.UI.UIApplication revit = commandData.Application;

            m_revit = revit;
            RotateFramingObjectsForm displayForm = new RotateFramingObjectsForm(this);

            displayForm.StartPosition = FormStartPosition.CenterParent;
            ElementSet selection = new ElementSet();

            foreach (ElementId elementId in revit.ActiveUIDocument.Selection.GetElementIds())
            {
                selection.Insert(revit.ActiveUIDocument.Document.GetElement(elementId));
            }
            bool isSingle            = true; //selection is single object
            bool isAllFamilyInstance = true; //all is not familyInstance

            // There must be beams, braces or columns selected
            if (selection.IsEmpty)
            {
                // nothing selected
                message = "Please select some beams, braces or columns.";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            else if (1 != selection.Size)
            {
                isSingle = false;
                try
                {
                    if (DialogResult.OK != displayForm.ShowDialog())
                    {
                        return(Autodesk.Revit.UI.Result.Cancelled);
                    }
                }
                catch (Exception)
                {
                    return(Autodesk.Revit.UI.Result.Failed);
                }
                //    return Autodesk.Revit.UI.Result.Succeeded;
                // more than one object selected
            }

            // if the selected elements are familyInstances, try to get their existing rotation
            foreach (Autodesk.Revit.DB.Element e in selection)
            {
                FamilyInstance familyComponent = e as FamilyInstance;
                if (familyComponent != null)
                {
                    if (StructuralType.Beam == familyComponent.StructuralType ||
                        StructuralType.Brace == familyComponent.StructuralType)
                    {
                        // selection is a beam or brace
                        string returnValue = this.FindParameter(AngleDefinitionName, familyComponent);
                        displayForm.rotationTextBox.Text = returnValue.ToString();
                    }
                    else if (StructuralType.Column == familyComponent.StructuralType)
                    {
                        // selection is a column
                        Location      columnLocation = familyComponent.Location;
                        LocationPoint pointLocation  = columnLocation as LocationPoint;
                        double        temp           = pointLocation.Rotation;
                        string        output         = (Math.Round(temp * 180 / (Math.PI), 3)).ToString();
                        displayForm.rotationTextBox.Text = output;
                    }
                    else
                    {
                        // other familyInstance can not be rotated
                        message = "It is not a beam, brace or column.";
                        elements.Insert(familyComponent);
                        return(Autodesk.Revit.UI.Result.Failed);
                    }
                }
                else
                {
                    if (isSingle)
                    {
                        message = "It is not a FamilyInstance.";
                        elements.Insert(e);
                        return(Autodesk.Revit.UI.Result.Failed);
                    }
                    // there is some objects is not familyInstance
                    message = "They are not FamilyInstances";
                    elements.Insert(e);
                    isAllFamilyInstance = false;
                }
            }

            if (isSingle)
            {
                try
                {
                    if (DialogResult.OK != displayForm.ShowDialog())
                    {
                        return(Autodesk.Revit.UI.Result.Cancelled);
                    }
                }
                catch (Exception)
                {
                    return(Autodesk.Revit.UI.Result.Failed);
                }
            }

            if (isAllFamilyInstance)
            {
                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            else
            {
                //output error information
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
Ejemplo n.º 3
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 Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
            ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.UI.UIApplication revit = commandData.Application;

            m_revit = revit;
            RotateFramingObjectsForm displayForm = new RotateFramingObjectsForm(this);
            displayForm.StartPosition = FormStartPosition.CenterParent;
            ElementSet selection = revit.ActiveUIDocument.Selection.Elements;
            bool isSingle = true;                   //selection is single object
            bool isAllFamilyInstance = true;  //all is not familyInstance

            // There must be beams, braces or columns selected
            if (selection.IsEmpty)
            {
                // nothing selected
                message = "Please select some beams, braces or columns.";
                return Autodesk.Revit.UI.Result.Failed;
            }
            else if (1 != selection.Size)
            {
                isSingle = false;
                try
                {
                    if (DialogResult.OK != displayForm.ShowDialog())
                    {
                        return Autodesk.Revit.UI.Result.Cancelled;
                    }
                }
                catch (Exception)
                {
                    return Autodesk.Revit.UI.Result.Failed;
                }
                //    return Autodesk.Revit.UI.Result.Succeeded;
                // more than one object selected
            }

            // if the selected elements are familyInstances, try to get their existing rotation
            foreach (Autodesk.Revit.DB.Element e in selection)
            {
                FamilyInstance familyComponent = e as FamilyInstance;
                if (familyComponent != null)
                {
                    if (StructuralType.Beam == familyComponent.StructuralType
                 || StructuralType.Brace == familyComponent.StructuralType)
                    {
                        // selection is a beam or brace
                        string returnValue = this.FindParameter(AngleDefinitionName, familyComponent);
                        displayForm.rotationTextBox.Text = returnValue.ToString();
                    }
                    else if (StructuralType.Column == familyComponent.StructuralType)
                    {
                        // selection is a column
                        Location columnLocation = familyComponent.Location;
                        LocationPoint pointLocation = columnLocation as LocationPoint;
                        double temp = pointLocation.Rotation;
                        string output = (Math.Round(temp * 180 / (Math.PI), 3)).ToString();
                        displayForm.rotationTextBox.Text = output;
                    }
                    else
                    {
                        // other familyInstance can not be rotated
                        message = "It is not a beam, brace or column.";
                        elements.Insert(familyComponent);
                        return Autodesk.Revit.UI.Result.Failed;
                    }
                }
                else
                {
                    if (isSingle)
                    {
                        message = "It is not a FamilyInstance.";
                        elements.Insert(e);
                        return Autodesk.Revit.UI.Result.Failed;
                    }
                    // there is some objects is not familyInstance
                    message = "They are not FamilyInstances";
                    elements.Insert(e);
                    isAllFamilyInstance = false;
                }
            }

            if (isSingle)
            {
                try
                {
                    if (DialogResult.OK != displayForm.ShowDialog())
                    {
                        return Autodesk.Revit.UI.Result.Cancelled;
                    }
                }
                catch (Exception)
                {
                    return Autodesk.Revit.UI.Result.Failed;
                }
            }

            if (isAllFamilyInstance)
            {
                return Autodesk.Revit.UI.Result.Succeeded;
            }
            else
            {
                //output error information
                return Autodesk.Revit.UI.Result.Failed;
            }
        }