display the function of each of a select floor's structural layers
Inheritance: System.Windows.Forms.Form
Exemplo n.º 1
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;

            // Get the selected floor
            UIDocument project    = revit.ActiveUIDocument;
            Selection  choices    = project.Selection;
            ElementSet collection = new ElementSet();

            foreach (ElementId elementId in choices.GetElementIds())
            {
                collection.Insert(project.Document.GetElement(elementId));
            }

            // Only allow to select one floor, or else report the failure
            if (1 != collection.Size)
            {
                message = "Please select a floor.";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            foreach (Element e in collection)
            {
                m_slab = e as Autodesk.Revit.DB.Floor;
                if (null == m_slab)
                {
                    message = "Please select a floor.";
                    return(Autodesk.Revit.UI.Result.Failed);
                }
            }

            // Get the function of each of its structural layers
            foreach (CompoundStructureLayer e in m_slab.FloorType.GetCompoundStructure().GetLayers())
            {
                // With the selected floor, judge if the function of each of its structural layers
                // is exist, if it's not exist, there should be zero.
                if (0 == e.Function)
                {
                    m_functions.Add("No function");
                }
                else
                {
                    m_functions.Add(e.Function.ToString());
                }
            }

            // Display them in a form
            StructuralLayerFunctionForm displayForm = new StructuralLayerFunctionForm(this);

            displayForm.ShowDialog();

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Run this sample now
        /// </summary>
        public void Run()
        {
            //
            // Get the selected floor
            Selection  choices    = m_doc.Selection;
            ElementSet collection = new ElementSet();

            foreach (var elementid in  choices.GetElementIds())
            {
                collection.Insert(m_doc.Document.GetElement(elementid));
            }

            //
            // Only allow to select one floor, or else report the failure
            if (1 != collection.Size)
            {
                MessageBox.Show("Please select a floor firstly.");
                return;
            }
            foreach (Element e in collection)
            {
                m_slab = e as Autodesk.Revit.DB.Floor;
                if (null == m_slab)
                {
                    MessageBox.Show("Please select a floor firstly.");
                    return;
                }
            }
            //
            // Get the function of each of its structural layers
            foreach (CompoundStructureLayer e in m_slab.FloorType.GetCompoundStructure().GetLayers())
            {
                // With the selected floor, judge if the function of each of its structural layers
                // is exist, if it's not exist, there should be zero.
                if (0 == e.Function)
                {
                    m_functions.Add("No function");
                }
                else
                {
                    m_functions.Add(e.Function.ToString());
                }
            }
            //
            // Display them in a form
            StructuralLayerFunctionForm displayForm = new StructuralLayerFunctionForm(this);

            displayForm.ShowDialog();
        }
Exemplo 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;

            // Get the selected floor
            UIDocument project = revit.ActiveUIDocument;
            Selection choices = project.Selection;
            ElementSet collection = choices.Elements;

            // Only allow to select one floor, or else report the failure
            if (1 != collection.Size)
            {
                message = "Please select a floor.";
                return Autodesk.Revit.UI.Result.Failed;
            }
            foreach (Element e in collection)
            {
                m_slab = e as Autodesk.Revit.DB.Floor;
                if (null == m_slab)
                {
                    message = "Please select a floor.";
                    return Autodesk.Revit.UI.Result.Failed;
                }
            }

            // Get the function of each of its structural layers
            foreach (CompoundStructureLayer e in m_slab.FloorType.GetCompoundStructure().GetLayers())
            {
                // With the selected floor, judge if the function of each of its structural layers
                // is exist, if it's not exist, there should be zero.
                if (0 == e.Function)
                {
                    m_functions.Add("No function");
                }
                else
                {
                    m_functions.Add(e.Function.ToString());
                }

            }

            // Display them in a form
            StructuralLayerFunctionForm displayForm = new StructuralLayerFunctionForm(this);
            displayForm.ShowDialog();

            return Autodesk.Revit.UI.Result.Succeeded;
        }