Whats wrong in my collector?

Hello,

i want all my active elements in view (BCF view, allready elements isolated there)

here is my code

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

collector = FilteredElementCollector(doc,doc.ActiveView.Id).ToElements()

OUT = collector

KR

Andreas

Add .WhereElementIsNotElementType().

collector = FilteredElementCollector(doc,doc.ActiveView.Id).WhereElementIsNotElementType().ToElements()
2 Likes

@Alban_de_Chasteigner

my view is the BCF Manager 3D view … could that be the reason ?

it is still the same result! should i prefilter like show only 3D elements ?


…thats actually weard stuff here :frowning:

KR

Andreas

hello, my hidden items are not collected like this

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

collector = FilteredElementCollector(doc,uidoc.ActiveView.Id).WhereElementIsNotElementType().ToElements()

OUT = collector

edit: sorry I was stupid, I didn’t save the python script between changes
doc.Actiview.Id and uidoc.Actiview.Id , there is no change between these 2 states
cordially
christian.stan

1 Like

@christian.stan ,

did also check with a “BCF-view” ?

…it still remains… for any reason it takes element that are not in the view, even with open/close dynamo

KR

Andreas

The other elements you’re seeing are Cameras, essentially view settings for other 3D views. You can filter them out with an ElementCategoryFilter() using the boolean overload. You could still have a few leftovers after that, depending on what all is in your view/project. You might also benefit from a WhereElementIsViewIndependent() filter as well.

This is why you have to be careful with true “all element” collectors. Just about everything in Revit is or has an element, often leaving you with a bunch of “extra” objects in your collector. The Dynamo node already filters out these extra categories.

3 Likes

@Nick_Boyts ,

thanks! i become “creative” regarding your ideas, BUT…

look at my code:

import clr

import System
from System.Collections.Generic import *

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
builtInCat = List[BuiltInCategory]()

builtInCat.Add(BuiltInCategory.OST_Walls)
builtInCat.Add(BuiltInCategory.OST_Floors)
builtInCat.Add(BuiltInCategory.OST_Columns)
builtInCat.Add(BuiltInCategory.OST_Roofs)

Filter = ElementMulticategoryFilter(builtInCat)

collector = FilteredElementCollector(doc,doc.ActiveView.Id).WherePasses(Filter).ToElements()
#collector = FilteredElementCollector(doc,doc.ActiveView.Id).WhereElementIsViewIndependent().ToElements()
#collector = FilteredElementCollector(doc,doc.ActiveView.Id).WhereElementIsNotElementType().ToElements()
#WhereElementIsViewIndependent()
OUT = collector

how to implement this boolean like “if unknown” false…

i got this :wink:

is this a way, how can limit my view to the categories that might be in the view ?

KR

Andreas


Categories_ = doc.Settings.Categories

model_cat = []

for c in Categories_:
	if c.CategoryType == CategoryType.Model:
		model_cat.append(Revit.Elements.Category.ById(c.Id.IntegerValue))
	else: continue
	
OUT = model_cat

this code works also, but can i map it like “Categories_.CurrentView”

Why are you wanting to filter out those elements? Isn’t that exactly what you want? You have roofs in your category filter and those elements are being included in the list. If you don’t want them just remove them from the filter.

1 Like

@Nick_Boyts ,

i know it for this view, but when i want it to use for other views, it could be also windows and curtiainwalls in the view…

so how can i set up my collector to all 3D Categories ? or is all “OST_” 3D Categories ?

in the case for the Roofs it does not work, it is still “Unknown”. I think because they are InPlaceFamilies.

I came to this

thats the code

import clr

import System
from System.Collections.Generic import *

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
builtInCat = List[BuiltInCategory]()

Categories_ = doc.Settings.Categories

model_cat = []

for c in Categories_:
	if c.CategoryType == CategoryType.Model:
		model_cat.append(Revit.Elements.Category.ById(c.Id.IntegerValue))
	else: continue
	
Categories_ = [x.Id for x in doc.Settings.Categories if x.CategoryType == CategoryType.Model]

catId = List[ElementId](Categories_)

Filter_ = ElementMulticategoryFilter(catId)

ModelElements = FilteredElementCollector(doc,doc.ActiveView.Id).WherePasses(Filter_).WhereElementIsNotElementType()
	
OUT = ModelElements

KR

Andreas

That’s where the WhereElementIsViewIndependent() filter comes in. View dependent elements are the elements specific to a view. View independent elements are the elements that exist in “model space” and are visible in all views (outside of filters and other view settings).

There are a handful of other view independent categories that are not model categories, but they don’t show up too often. It’s easier to filter them out rather than specify everything you want to include. This is where you can use the ElementCategoryFilter() with the boolean overload to exclude Camera category elements (and any others you may have).

The object type is unknown, which is probably an issue with the wrapper, but you can see python is returning the element.

1 Like

@Nick_Boyts

it looks like this

thats the ZeroTouch resulst

grafik

KR

Andreas

Correct, but you’re only filtering out one of the two issues you’re dealing with. That is only removing the objects that are view dependent. There should only be one by default. All the additional elements you’re seeing are the Camera elements from other 3D views. You have to filter out that category with an additional filter.


You need to include both filters:

collector = FilteredElementCollector(doc,doc.ActiveView.Id)
ecf = ElementCategoryFilter(BuiltInCategory.OST_Cameras, True)
filtered = collector.WhereElementIsViewIndependent().WherePasses(ecf).ToElements()
4 Likes

Hi,
+1 for remove some extra categories


import clr
import System

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

builtInCat = List[BuiltInCategory]([BuiltInCategory.OST_Cameras, BuiltInCategory.OST_SectionBox])
not_filterCat = ElementMulticategoryFilter(builtInCat, True)

collector = FilteredElementCollector(doc,doc.ActiveView.Id).WherePasses(not_filterCat).ToElements()

OUT = collector
2 Likes