I wanted to answer the ISelectionFilter question because I like this interface, however I don't believe it is appropriate for selecting views.
My alternative solution would be to expand each element via LINQ and read the ViewType property as below. Probably would be similar in performance to a combination of quick and slow filter. The below is more generic for getting views of various types. For the C# version I converted from VB and filled in the gaps of the LINQ expression (therefore C# version may have issues unknown to me).
e.g. I think the 'v == null == false' could have come out better (!=).
VB version
Public Shared Function AllViewsOfType(Doc As Document, VT As ViewType, Optional ReturnViewElementTypes As Boolean = False, _
Optional ReturnViewTemplates As Boolean = False) As List(Of ElementId)
Dim ECF As New ElementClassFilter(GetType(View))
Dim FEC As New FilteredElementCollector(Doc)
Dim V_EIDs As List(Of ElementId) = Nothing
If ReturnViewElementTypes = True Then
V_EIDs = FEC.WherePasses(ECF).WhereElementIsElementType.ToElementIds
Else
V_EIDs = FEC.WherePasses(ECF).WhereElementIsNotElementType.ToElementIds
End If
Dim Ien As IEnumerable(Of ElementId)
Ien = From EID As ElementId In V_EIDs
Let V As View = TryCast(Doc.GetElement(EID), View)
Where V Is Nothing = False
Where V.ViewType = VT AndAlso V.IsTemplate = ReturnViewTemplates
Select EID
Return Ien.ToList
End Function
Public Shared Function ExampleUse(Doc As Document) As List(Of ElementId)
Return AllViewsOfType(Doc, ViewType.Legend)
End Function
C# version.
public static List<ElementId> AllViewsOfType(Document Doc, ViewType VT, bool ReturnViewElementTypes = false, bool ReturnViewTemplates = false)
{
ElementClassFilter ECF = new ElementClassFilter(typeof(View));
FilteredElementCollector FEC = new FilteredElementCollector(Doc);
List<ElementId> V_EIDs = null;
if (ReturnViewElementTypes == true) {
V_EIDs = FEC.WherePasses(ECF).WhereElementIsElementType.ToElementIds;
} else {
V_EIDs = FEC.WherePasses(ECF).WhereElementIsNotElementType.ToElementIds;
}
IEnumerable<ElementId> Ien = default(IEnumerable<ElementId>);
Ien = from EID in V_EIDs
let V = Doc.GetElement(EID) as View
where V == null == false
where V.ViewType == VT && V.IsTemplate == ReturnViewTemplates
select EID;
return Ien.ToList;
}
public static List<ElementId> ExampleUse(Document Doc)
{
return AllViewsOfType(Doc, ViewType.Legend);
}