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]
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.
⌨️ Happy Coding!
— Erik Frits
📩 Join Revit API Newsletter
Meanwhile, you will be receiving Newsletter with useful Tips & Tricks for Revit API
🙌 Thank You!
Confirm Your Email.
Check your inbox, you should receive a confirmation email to be added to the list.
📅 I usually send out my emails on Sundays, see you then👋