2011-06-30 102 views
0

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

我们有一个木梁系列,我只需要修改属于木材家族一部分的选定元素。我在网上查找过,但找不到任何能告诉我如何去做的事。我新来修复。

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

回答

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();