Begginer to Python: 'FilteredElementCollector' is not defined Error


I’m trying to follow the PyRevit tutorial.
In the first example he tries to show how to collect all elements of the wall category from within the Interactive Revit Python Shell. I have already configured the RPS startup script to be the file this file he offers in the course:
For some reason though, I get this error. Please see image attached:

Thanks for the help in advance.


Just to check if your startup script is working,
Did you check just typing >>> el
did that returned all the selected items if <5 ?

Hi Saju.
It works. When I select elements and type “el” I see that the first element is selected.

please add the below lines into your code at the beginning and check.

import clr
from Autodesk.Revit.DB import *
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

OK. It worked once, but now It’s giving me this error:

experts will reply. Please close and open the console and try

OK. I just needed to import the DB library where the FilteredElementCollector class is found.
from Autodesk.Revit import DB

1 Like

thank you brother.
had the exact same issue.
i would like to understand why this happened? is it possible that the init script got somehow corrupted and it didn’t read the imports?

Ok, I found out to anyone interested: The correct init script that you need is in the ‘revisions’ page, here:

This one will import everything in the Autodesk.Revit.DB Namespace.
Thanks @eirannejad for the great tutorials! :slight_smile:

Thanks. Ya just use this init script with RPS and then use the DB namespace to access all DB types like DB.FilteredElementCollector

Generally importing all types into your local script namespace is a bad idea and takes execution time and also creates name conflicts. e.g. from Autodesk.Revit.DB import * is bad