Admits elements that satisfy two conditions:
- The element's category must be one of a certain set of allowed categories.
- The element must pass a series of filter rules.
Namespace:
Autodesk.Revit.DB
Assembly:
RevitAPI
(in RevitAPI.dll) Version: 17.0.0.0 (17.0.1090.0)
Since:
2011
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Examples
Copy
C#
public static void CreateViewFilter(Document doc, View view)
{
List<ElementId> categories = new List<ElementId>();
categories.Add(new ElementId(BuiltInCategory.OST_Walls));
List<FilterRule> filterRules = new List<FilterRule>();
using (Transaction t = new Transaction(doc, "Add view filter"))
{
t.Start();
// Create filter element assocated to the input categories
ParameterFilterElement parameterFilterElement = ParameterFilterElement.Create(doc, "Example view filter", categories);
// Criterion 1 - wall type Function is "Exterior"
ElementId exteriorParamId = new ElementId(BuiltInParameter.FUNCTION_PARAM);
filterRules.Add(ParameterFilterRuleFactory.CreateEqualsRule(exteriorParamId, (int)WallFunction.Exterior));
// Criterion 2 - wall height > some number
ElementId lengthId = new ElementId(BuiltInParameter.CURVE_ELEM_LENGTH);
filterRules.Add(ParameterFilterRuleFactory.CreateGreaterOrEqualRule(lengthId, 28.0, 0.0001));
// Criterion 3 - custom shared parameter value matches string pattern
// Get the id for the shared parameter - the ElementId is not hardcoded, so we need to get an instance of this type to find it
Guid spGuid = new Guid("96b00b61-7f5a-4f36-a828-5cd07890a02a");
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(Wall));
Wall wall = collector.FirstElement() as Wall;
if (wall != null)
{
Parameter sharedParam = wall.get_Parameter(spGuid);
ElementId sharedParamId = sharedParam.Id;
filterRules.Add(ParameterFilterRuleFactory.CreateBeginsWithRule(sharedParamId, "15.", true));
}
parameterFilterElement.SetRules(filterRules);
// Apply filter to view
view.AddFilter(parameterFilterElement.Id);
view.SetFilterVisibility(parameterFilterElement.Id, false);
t.Commit();
}
}
Copy
VB.NET
Public Shared Sub CreateViewFilter(doc As Document, view As View)
Dim categories As New List(Of ElementId)()
categories.Add(New ElementId(BuiltInCategory.OST_Walls))
Dim filterRules As New List(Of FilterRule)()
Using t As New Transaction(doc, "Add view filter")
t.Start()
' Create filter element assocated to the input categories
Dim parameterFilterElement__1 As ParameterFilterElement = ParameterFilterElement.Create(doc, "Example view filter", categories)
' Criterion 1 - wall type Function is "Exterior"
Dim exteriorParamId As New ElementId(BuiltInParameter.FUNCTION_PARAM)
filterRules.Add(ParameterFilterRuleFactory.CreateEqualsRule(exteriorParamId, CInt(WallFunction.Exterior)))
' Criterion 2 - wall height > some number
Dim lengthId As New ElementId(BuiltInParameter.CURVE_ELEM_LENGTH)
filterRules.Add(ParameterFilterRuleFactory.CreateGreaterOrEqualRule(lengthId, 28.0, 0.0001))
' Criterion 3 - custom shared parameter value matches string pattern
' Get the id for the shared parameter - the ElementId is not hardcoded, so we need to get an instance of this type to find it
Dim spGuid As New Guid("96b00b61-7f5a-4f36-a828-5cd07890a02a")
Dim collector As New FilteredElementCollector(doc)
collector.OfClass(GetType(Wall))
Dim wall As Wall = TryCast(collector.FirstElement(), Wall)
If wall IsNot Nothing Then
Dim sharedParam As Parameter = wall.Parameter(spGuid)
Dim sharedParamId As ElementId = sharedParam.Id
filterRules.Add(ParameterFilterRuleFactory.CreateBeginsWithRule(sharedParamId, "15.", True))
End If
parameterFilterElement__1.SetRules(filterRules)
' Apply filter to view
view.AddFilter(parameterFilterElement__1.Id)
view.SetFilterVisibility(parameterFilterElement__1.Id, False)
t.Commit()
End Using
End Sub
Inheritance Hierarchy
System
Object
Autodesk.Revit.DB Element
Autodesk.Revit.DB FilterElement
Autodesk.Revit.DB ParameterFilterElement
Autodesk.Revit.DB Element
Autodesk.Revit.DB FilterElement
Autodesk.Revit.DB ParameterFilterElement