Get all elements from model efficiently

Hello All,
I have used Revit API to get all the model elements faster and efficiently

But I do know know how can I avoid some of these elements that do not have any geometry in the model for example such as Detail Component, Duct Systems etc.
Basically I want to work with all the elements that have at least some geometry which defines that that’s a model element and not an annotative element.

#Importing necessary libraries
import clr
import System
from System.Collections.Generic import List
#Referencing Revit API
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, ElementMulticategoryFilter, CategoryType
#Reference to RevitServices to get current document and app
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
#accesing the current Revit Document
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
app = uidoc.Application.Application
categories = doc.Settings.Categories
# Creating a new category set for model categories
cateset = app.Create.NewCategorySet()
# Iterating through categories and adding model categories to the category set
for c in categories:
	if c.CategoryType == CategoryType.Model:
		if c.SubCategories.Size > 0 or c.CanAddSubcategory:
			if c.AllowsBoundParameters:
				cateset.Insert(c)
# Converting the category set to a list of BuiltInCategory
cat_list = List[BuiltInCategory](BuiltInCategory(i.Id.IntegerValue) for i in cateset)
# Creating a multicategory filter using the list of model categories
catFilter = ElementMulticategoryFilter(cat_list,False)
# Collecting elements that pass the multicategory filter
OUT = FilteredElementCollector(doc).WherePasses(catFilter).WhereElementIsNotElementType().ToElements()

I recommend making a new 3d view, stripping any template, using a filtered element collector to get all elements visible in that view, and then rolling back the view creation.

It won’t catch design options and some other edge cases, but it will catch anything with 3d geometry.

3 Likes

I tried it, but getting elements visible in a view was not fast enough.
My goal is to collect all model elements as quickly as possible (these elements will be processed for generating unique tagging, extracting the location etc.).
I created a list of Model Categories that I wanted to exclude from the main list of Model categories, removed them using for loop, and achieved the desired outcome with new list of categories.