Revitapi Python
Revitapi Python
FilteredElementCollector
This class is used to search, filter and iterate through a set of elements.
There are many methods available to simplify this process, but we can
also dive deeper and create our own custom filters, which we will look
into later in this Guide.
If you’re new to RevitAPI and want to start writing your own scripts,
you’ll need to learn how to use FilteredElementCollector. It’s a class
that is used nearly in every script that you are going to write .
You can learn more about available methods and Filters by looking
inside of revitapidocs.com. That’s an online RevtiAPI documentation,
which we need to refference from time to time.
FilteredElementCollector Anatomy
This is a typical use of FilteredElementCollector()
Let’s break it down to pieces.
Optional*
A B C D
Create a collector Filter by Category/Class Filter to Types/Instances To Elements/ElementIds
To create a collector, first we need Secondly, we need to filter by By now, we are getting both Lastly, we just need to convert
to provide a Document from category or class. instances and types. this collector into a list of usable
where we want to get elements Some Classes have the same We can use FEC methods to objects.
as an argument. category, and some elements filter down selection to
are not possible to get with instances or Types. In most cases I use
In addition, we can also provide OfClass method. .ToElements() ,but sometimes
the View.Id as an optional These methods do not take any you might prefer to use
second argument if you want to .OfCategory(BuiltInCategory) arguments. .ElementIds()
limit your selection to visible .OfClass(type)
elements in the given view.
This is a common way of getting your Elements from a project. We define a Category, Filter only to Instances and returning a list of Elements.
PAGE 5
Modify here to Change Category Here. Remove Not if Change here if you
Select from View RevitAPI Autocomplete you want Types want ElementIds.
will show you all the
BuiltInCategories
PAGE 6 MADE BY ERIK FRITS
When you look inside your elements with RevitLookup, you can
see a menu with all the properties and methods available for the
element
Simple Examples
To prove you that it really is that simple, Look at the snippet on the
right with different examples of getting Elements.
ElementLevelFilter
This filter is used to match elements by
their associated level. We just need to
provide Level.Id and filter is ready.
ElementIsCurveDrivenFilter
This filter is used to match elements
which are curve driven.
The term «curve driven» indicates that
the element’s Location property is a
LocationCurve.
Examples:
- Walls
- Beams
- Curve elements...
ElementStrucuralTypeFilter:
This filter is used to find elements
matching a structural type.
ElementParameterFilter
Evaluator
Evaluator is just a class representing
equal, less, more, etc...
You can see them on the right.
ElementParameterFilter: Text
Get Elements By Type/Family Name
Let’s create a Filter to get elements
by Type or Family Name
Create a Rule
Creating a rule is not hard as it seems.
FilterStringRule takes 4 arguments and you
can see a snippet on the right.
You’ll find that once you get the hang of it, it’s
super easy to make rules in Revit. You just need
to practice a few times, and then it will become
natural to use.
Create Filter
Creating filter is simple, just provide a rule that
you want to apply and it’s done.
ElementParameterFilter: Numeric
Get Walls with Height of 50cm
ElementParameterFilter: ElementId
Get Elements of the same category
LogicalAndFilter
Let’s say we want to use 2 filters
and both of them should
evaluate to True.
FILTER_1:
Get elements that contain a
word ‘wood’ in Type Name and
it’s not case sensetive.
FILTER_2:
Get all elements that have a
thickness of Greater than 10cm.
LogicalAndFilter:
Since we only have 2 filters, we
can just pass them
as 2 arguments.
PAGE 19
Special Elements
Finally, there are some elements that we can’t get with
FilteredElementCollector, because they have their own
special classes to get them.
Here are a few examples below.
Unfortunately I could not remember more,
so if you stuble on a category of elements that
you can’t get even after reading this guide,
Let me know.
It might contribute to the second edition of this guide.
THANK YOU
You made it to the end!
What’s Next?
I would appreciate if you You can follow me on: I would appreciate if you
spread the word on social leave some feedback
media about this guide so it www.linkedin.com/in/erik-frits/ about this Guide!
can reach even more people. www.youtube.com/c/ErikFrits [email protected]