Last Chance To Claim LIFETIME ACCESS. [~30 Seats left]

Sep 20, 2022

Get Warnings with RevitAPI

How to get Warnings and associated elements with Revit API + Python.

Get and Sort Warnings by Type

Getting warning is not complicated, but it would make more sense to sort them by warnings types. Whenever you are going to work with warnings, you will want to focus on some types more than on others. So let's get them and sort in a dictionary.

from collections import defaultdict

all_warnings = defaultdict(list)

# Sort Warnings by Type
for w in doc.GetWarnings():
    description = w.GetDescriptionText()
    all_warnings[description].append(w)

Now we have a dictionary that has warning description as a Key and a list of all warnings as a value.
We might want to get elements associated with these warnings with the following snippet.

for warning_type in all_warnings:
    warnings = all_warnings[war_typ]

    for w in warnings:
        element_ids = list(w.GetFailingElements()) + list(w.GetAdditionalElements())
        elements = [doc.GetElement(e_id) for e_id in element_ids]

Verify Element

Lastly, before making changes to the set of associated elements, make sure that these elements are modifiable.
For example, if you would want to Hide or Isolate these elements, you might need to check if that would even be possible.

e.g. element.CanBeHidden(View)


Join Newsletter

📩 You will be added to Revit API Newsletter

Join Us!

which is already read by 7200+ people!

Ready to become Revit Hero for your office? Learn Revit API!

Join this comprehensive course that will guide you step by step on how to create your dream tools for Revit that save time.