我需要按家庭过滤所选元素。
我们有一个木梁系列,我只需要修改属于木材系列的选定元素。我看过网上但我找不到任何能告诉我怎么做的东西。我是新来的。
//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);
答案 0 :(得分: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();