Get all elements from model

I have a question is it possible to get all elements from the durrent model?
I want to get all elements without selecting or using All Elements in Active View.
So basically I want a list with all made Revit model elements.
I have tried something with Python but i can only make it work when I have a view.

afbeelding

My code:

import clr

clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure 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

#Preparing input from dynamo to revit

def unwraplist(input):
inputtolist = input if isinstance(input, list) else [input]
unwrap = UnwrapElement(inputtolist)
return unwrap

views = unwraplist(IN[0])

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

lijstElement =
lijstElementnamen =

for view in views:
geldigeElementen = FilteredElementCollector(doc, view.Id).WhereElementIsNotElementType()
elementenInView = geldigeElementen.ToElements()

for element in elementenInView:
		lijstElementnamen.append(element.Name)
		lijstElement.append(doc.GetElement(element.Id))

TransactionManager.Instance.TransactionTaskDone()

OUT = lijstElement

1 Like

You don’t need to use a view as input for the FilteredElementCollector. Have a look at the RevitAPIdocs. It also has a constructor that only takes a Document as an argument.

1 Like

@Lunzur As suggested by @johanboo

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

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

OUT = FilteredElementCollector(doc).WhereElementIsNotElementType().ToElements()
3 Likes

Hey AmolShah, thanks I got all the elements
I have another question. With this code I get also the elements which are not modled is it possible to get only the modled elements?
Now I even get elements which aren not modled like “Electrical Load Classification Parameter Element”

@Lunzur This should get you all the elements from All Model Categories in your document.

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

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

#allElements = FilteredElementCollector(doc).WhereElementIsNotElementType().WhereElementIsViewIndependent().ToElements()
allElements = FilteredElementCollector(doc).WhereElementIsNotElementType().ToElements()

filteredElements = []

for element in allElements:
	if element.Category != None and element.Parameters.Size > 0  and element.HasPhases:
		if element.Category.CategoryType == CategoryType.Model and (element.Category.SubCategories.Size > 0 or element.Category.CanAddSubcategory):
			filteredElements.append(element)

OUT = filteredElements

This works for me on my project but you might have to modify the if conditions based on the output you require.

This topic should guide you in the right direction to help you with the if conditions: The Building Coder: Retrieving All Model Elements

7 Likes

Hey AmolShah,
WOW thank you very much It works realy well, the script does what I want.
Do you know any good tutoriols for Dynamo Python, I just recentrly start learning python

@Lunzur Glad that it worked out for you.

I think this topic has some good resources to get started with:

2 Likes

Another quick reply :smile:
Thanks I will definitely look in to it, have a nice day AmolShah

1 Like