简体   繁体   中英

Use python to get view filters for views in Revit project

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

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:

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM