过滤器过滤元素:
Document document = revit.Application.ActiveUIDocument.Document;
FilteredElementCollector collector = new FilteredElementCollector(document);
- 快速过滤
collector.OfCategory(BuiltInCategory.OST_Walls).ofClass(typeof(FamilyInstance))
OfCategory过滤类别,包括FamilySymbol及FamilyInstance,先通过OfCategory进行过滤可以提高效率,通过OfClass可以获取实例或者类型。
- 通用过滤
LogicalAndFilter doorInstancesFilter =new LogicalAndFilter(familyInstanceFilter, doorsCategoryfilter);
FilteredElementCollector collector = new FilteredElementCollector(document);
ICollection<ElementId> doors = collector.WherePasses(doorInstancesFilter).ToElementIds();
框选构件并筛选构件
public class WallFilter : ISelectionFilter
{
public bool AllowElement(Element element)
{
if (element is Wall)
{
return true;
}
return false;
}
public bool AllowReference(Reference refer, XYZ point)
{
return false;
}
}
// code in command
IList<Element> elements = uiDoc.Selection.PickElementsByRectangle(new WallFilter(), "请选择墙");
foreach (Element element in elements)
{
// do something
}