0

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

我们有一个木梁族,我只需要修改属于木梁族的选定元素。我在网上查看过,但找不到任何可以告诉我如何操作的东西。我是新来的。

//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);
4

1 回答 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();
于 2011-07-04T07:30:08.063 回答