过滤器分为选择过滤器与规则过滤器
规则过滤器可以看我之前写的这一篇文章:
Revit二次开发在项目中给链接模型附加过滤器
选择过滤器顾名思义就是可以将选择的构件ID集合传入并加入到视图过滤器中,有一些场景需要对某些构件进行过滤选择,但是没有共同的逻辑规则进行筛选的情况下可以选择使用选择过滤器.
下面是我的代码,增加了截面填充突然与实体填充样式设置的代码:
var selectionFilter = SelectionFilterElement.Create(doc, "OutRange");selectionFilter.SetElementIds(targetElementIds);doc.ActiveView.AddFilter(selectionFilter.Id);var graphics = doc.ActiveView.GetFilterOverrides(selectionFilter.Id);graphics.SetCutBackgroundPatternColor(new Autodesk.Revit.DB.Color(255, 0, 0));graphics.SetCutBackgroundPatternId(PatternId(doc));graphics.SetCutForegroundPatternColor(new Autodesk.Revit.DB.Color(255, 0, 0));graphics.SetCutForegroundPatternId(PatternId(doc));doc.ActiveView.SetFilterOverrides(selectionFilter.Id, graphics);doc.ActiveView.SetFilterVisibility(selectionFilter.Id, true);
获取实体填充PatternId
的方法一起传上来:
/// <summary>
/// 获取实体填充ID
/// </summary>
/// <param name="document"></param>
/// <returns></returns>
private ElementId PatternId(Document document)
{var collector = new FilteredElementCollector(document);collector.OfClass(typeof(FillPatternElement));var fillPatternElement =collector.First(q => (q as FillPatternElement).GetFillPattern().IsSolidFill) as FillPatternElement;return fillPatternElement.Id;
}
选择过滤器(SelectionFilterElement Class)的API: