获取Revit中的一个元素的参数值

Revit二次开发基础,使用VS对其进行开发,要获取其中的一个元素,可以参考一下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Windows.Media.Imaging;

namespace Document_Selection
{
    [Autodesk.Revit.Attributes.Transaction(TransactionMode.ReadOnly)]
    public class Document_selection:IExternalCommand
    {
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                //Select some elements in Revit before invoking this command

                //Get the handle of current document

                UIDocument uidoc = commandData.Application.ActiveUIDocument;

                //Get the element selection of current document

                Selection selection = uidoc.Selection;
                ElementSet collection = selection.Elements;

                if (0 == collection.Size)
                {
                    //如果没有元素被选中
                    TaskDialog.Show("Revit", "you have not seleced any elements");
                }
                else
                {
                    String info = "Ids if selected elements in the document aer:";
                    foreach (Element elem in collection)
                    {
                        info += "\n\t" + elem.Id.IntegerValue;
                    }
                    TaskDialog.Show("Revit", info);
                }

            }
            catch (Exception e)
            {
                message = e.Message;
                return Autodesk.Revit.UI.Result.Failed;
            }
            return Autodesk.Revit.UI.Result.Succeeded;
        }
    }
}

找到被选中的元素,就可以获取其属性,参数。

你可能感兴趣的:(Revit二次开发)