Use python to get view filters for views in Revit project

2k views Asked by At

I would like to be able to find all of the view filters in my project that are not being used.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

from System.Collections.Generic import *

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

#collect all views in model
collector = FilteredElementCollector(doc)
views = collector.OfClass(View).ToElements()
areaPlans = []

#collect all views filters in the model
collector = FilteredElementCollector(doc)
filters = collector.OfClass(ParameterFilterElement).ToElements()
#viewFilters = []

#filter out view templates
for i in views:
    if not i.IsTemplate:
        if i.ViewType == ViewType.AreaPlan:
            areaPlans.append(i.ToDSType(True))
        else:
            continue

bipViewFilter = filters

#Assign your output to the OUT variable.
OUT = bipViewFilter, areaPlans
2

There are 2 answers

0
konrad On

Here's one way you can achieve what you need:

# Import Element wrapper extension methods
import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

# first collect all of the views in a project
allViews = FilteredElementCollector(doc).OfClass(View).ToElements()

# filter out just the Area Plans
areaPlans = []
for i in allViews:
    if not i.IsTemplate and i.ViewType == ViewType.AreaPlan:
        areaPlans.append(i)

# extract filters used in all area plans
if len(areaPlans) != 0:
    viewFilters = [[] for i in range(len(areaPlans))]
    for index, item in enumerate(areaPlans):
        filters = item.GetFilters()
        if len(filters) != 0:
            for j in filters:
                viewFilters[index].append(doc.GetElement(j))


OUT = areaPlans, viewFilters

My understanding was that you need a way to extract only View Filters that were applied to Area Plans. This is a two step process where you can get Area Plans and then extract all View Filters for each view. You get something like this:

enter image description here

0
dkam47 On

One additional step was added to filter for the unused View Filters. Collected all View Filters in document and used a 'SetDifference' node to get filters that were not being currently used.