0

I'm trying to use a FilteredElementCollector inside my pyRevit script to collect all views (sections, elevations, plan callouts etc.) in the active view.

from pyrevit.framework import clr
from pyrevit import revit, DB

clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')

from Autodesk.Revit.DB import *
from pyrevit import forms

doc = __revit__.ActiveUIDocument.Document

view = doc.ActiveView
AllStuff = FilteredElementCollector(doc,doc.ActiveView.Id).WhereElementIsNotElementType().ToElements()

AllViews = []

try:
    for x in AllStuff:
        if "View" in x.Category.Name:
            AllViews.append(x)

This will return some, but not all of the views. For example, some sections are included but others are not and I can't tell why.

If I add ".OfCategory(BuiltInCategory.OST_Views)" I get nothing at all. Do I need to break it down into several more specific categories? Thanks for any help.

1 Answers1

1

There is no view in FilteredElementCollector(doc, doc.ActiveView.Id), you can see it by doing :

for el in FilteredElementCollector(doc, doc.ActiveView.Id):
    print(el)

There is an Element which is not of category OST_Views and is not a view even if it has the same name as your view. To see this you can use RevitLookUp. Lookup

I found a way to retrieve the actual view (I don't know any other way at the moment) by looking at VIEW_FIXED_SKETCH_PLANE BuiltInParameter which refer to the SketchPlane whiche reference the actual view as Element.OwnerViewId. Then you can make sure that the element is of class View :

for el in FilteredElementCollector(doc,doc.ActiveView.Id):
    sketch_parameter = el.get_Parameter(BuiltInParameter.VIEW_FIXED_SKETCH_PLANE)
    # If parameter do not exist skip the element
    if not sketch_parameter:
        continue
    view_id = doc.GetElement(sketch_parameter.AsElementId()).OwnerViewId
    view = doc.GetElement(view_id)
    if isinstance(view, View):
        print(view)
Cyril Waechter
  • 517
  • 4
  • 16
  • Thanks a lot for your reply Cyril. I should have been more clear with what I want to do: my end goal is to hide the sections, callouts etc. in the active view that ARE NOT referring to another view (in other words, the originals). So if the sections, elevations etc. that I see in a floor plan are not of the category "View" I need to find a different category to collect. On that front thanks for showing me Revit Lookup. I hadn't heard of it and it looks really useful. – Matt Johnson Feb 04 '19 at 21:26
  • To follow up: Revit Lookup showed me how to find the category (Viewer) and parameter values that I need. Thank you so much! – Matt Johnson Feb 04 '19 at 21:40