作者:24吴梦琦_581 | 来源:互联网 | 2023-09-01 17:25
本文章代码功能是获取当前项目文件中所有的标准族实例,及载入族的族名称,并显示出来,效果如下:
代码如下
using System.Collections.Generic;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Loadfamily
{
[Transaction(TransactionMode.Manual)]
public class ExamineFamily : IExternalCommand
{
List list1 = new List();
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document doc = commandData.Application.ActiveUIDocument.Document;
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(FamilyInstance));//过滤获取到当前文件中所有的族实例
IList CollectorList = collector.ToElements();
string famliyName = "";
int i1 = 0;//用来记录项目中族实例个数
for (int i = 0; i {
FamilyInstance fi = CollectorList[i] as FamilyInstance;
string ss = fi.Symbol.FamilyName;
if (list1.Contains(ss) == false)//合并相同族文件名称
{
list1.Add(ss);
famliyName += ss + "\n";
}
i1++;
}
TaskDialog.Show("我是标题", "载入的族文件有:"+"\n"+famliyName + "项目中一共" + i1+ "个族实例");
return Result.Succeeded;
}
}
}