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()