A filter element that stores an explicit list of ElementIds.
Only elements whose ElementIds are in this list will pass the filter.
Namespace:
Autodesk.Revit.DB
Assembly:
RevitAPI
(in RevitAPI.dll) Version: 21.0.0.0 (21.1.1.109)
Since:
2013
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Examples
Copy
C#
public static void CreateSelectionFilter(Document doc, View view)
{
// find room tags in this view
FilteredElementCollector collector = new FilteredElementCollector(doc, view.Id);
collector.WherePasses(new RoomTagFilter());
// collect tags whose room number matches criteria
List<ElementId> tagIds = new List<ElementId>();
foreach (RoomTag tag in collector.Cast<RoomTag>())
{
int number = Int32.Parse(tag.Room.Number);
if (number % 3 == 0)
{
tagIds.Add(tag.Id);
}
}
using (Transaction t = new Transaction(doc, "Create SelectionFilterElement"))
{
t.Start();
// Create selection filter and assign ids
SelectionFilterElement filterElement = SelectionFilterElement.Create(doc, "Room tags filter");
filterElement.SetElementIds(tagIds);
ElementId filterId = filterElement.Id;
// Add the filter to the view
view.AddFilter(filterId);
doc.Regenerate();
// Use the existing graphics settings, and change the color to Blue
OverrideGraphicSettings overrideSettings = view.GetFilterOverrides(filterId);
overrideSettings.SetProjectionLineColor(new Color(0x00, 0x00, 0xFF));
view.SetFilterOverrides(filterId, overrideSettings);
t.Commit();
}
}
Copy
VB.NET
Public Shared Sub CreateSelectionFilter(doc As Document, view As View)
' find room tags in this view
Dim collector As New FilteredElementCollector(doc, view.Id)
collector.WherePasses(New RoomTagFilter())
' collect tags whose room number matches criteria
Dim tagIds As New List(Of ElementId)()
For Each tag As RoomTag In collector.Cast(Of RoomTag)()
Dim number As Integer = Int32.Parse(tag.Room.Number)
If number Mod 3 = 0 Then
tagIds.Add(tag.Id)
End If
Next
Using t As New Transaction(doc, "Create SelectionFilterElement")
t.Start()
' Create selection filter and assign ids
Dim filterElement As SelectionFilterElement = SelectionFilterElement.Create(doc, "Room tags filter")
filterElement.SetElementIds(tagIds)
Dim filterId As ElementId = filterElement.Id
' Add the filter to the view
view.AddFilter(filterId)
doc.Regenerate()
' Use the existing graphics settings, and change the color to Blue
Dim overrideSettings As OverrideGraphicSettings = view.GetFilterOverrides(filterId)
overrideSettings.SetProjectionLineColor(New Color(&H0, &H0, &Hff))
view.SetFilterOverrides(filterId, overrideSettings)
t.Commit()
End Using
End Sub
Inheritance Hierarchy
System
Object
Autodesk.Revit.DB Element
Autodesk.Revit.DB FilterElement
Autodesk.Revit.DB SelectionFilterElement
Autodesk.Revit.DB Element
Autodesk.Revit.DB FilterElement
Autodesk.Revit.DB SelectionFilterElement