概要:
1.读取在Revit中选中的元素参数,并且显示在TaskDialog上。
2.把元素的类型的参数信息显示出来;
3.并且获取元素的族名称。
实现代码:
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary8
{
[TransactionAttribute(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument; //激活用户文档
Document revitDoc = uiDoc.Document; //获取Revit文档进行元素处理
var elemList = uiDoc.Selection.GetElementIds().ToList();//获得用户在Revit中选中的元素的集合
System.Collections.IList list = elemList;
for (int i1 = 0; i1 < list.Count; i1++) //遍历选中的每一个元素
{
Element selElem = uiDoc.Document.GetElement(elemList[i1]);//通过Id获得document中的元素
ElementType type = revitDoc.GetElement(selElem.GetTypeId()) as ElementType; //获取元素类型
string str = "元素名称:" + type.FamilyName + "\n" + "元素类型:" + type.Name;
TaskDialog.Show("元素参数", str);
}
return Result.Succeeded;
}
}
}
效果: