Revit 系列和过滤元素

问题描述 投票:0回答:1

我需要按系列过滤所选元素。

我们有一个木梁系列,我只需修改属于木梁系列的选定元素。

//get all instaces if family objects
FilteredElementCollector familyInstanceCollector = 
  new FilteredElementCollector(doc);

familyInstanceCollector.OfClass(typeof(FamilyInstance))
  .WherePasses(new FamilySymbolFilter(new ElementId(140519)));

MessageBox.Show(familyInstanceCollector.Count<Element>().ToString());

foreach (Element element in familyInstanceCollector)
  MessageBox.Show(element.Name);
revit-api
1个回答
3
投票

我不确定创建这样的新 ElementId 是否有效,并且我不确定您是否可以预测跨项目的 ElementId?最好的方法是执行过滤器来搜索您正在寻找的系列符号首先,然后使用该结果来查找实例。

查看 SDK 中提供的 .chm 文件,以下是其中的示例:

// Creates a FamilyInstance filter for elements that are family instances of the given    family symbol in the document

// Find all family symbols whose name is "W10X49"
FilteredElementCollector collector = new FilteredElementCollector(document);
collector = collector.OfClass(typeof(FamilySymbol));

// Get Element Id for family symbol which will be used to find family instances
var query = from element in collector where element.Name == "W10X49" select element;
List<Element> famSyms = query.ToList<Element>();
ElementId symbolId = famSyms[0].Id;

// Create a FamilyInstance filter with the FamilySymbol Id
FamilyInstanceFilter filter = new FamilyInstanceFilter(document, symbolId);

// Apply the filter to the elements in the active document
collector = new FilteredElementCollector(document);
ICollection<Element> familyInstances = collector.WherePasses(filter).ToElements();
© www.soinside.com 2019 - 2024. All rights reserved.