Resources
Summary
Revit API Changes
Every year we get a new version of Revit that has a few new/updated features. And so does Revit API.
There is a high chance that you use multiple Revit versions in your office, so it's good to prepare your scripts for possible changes.
💡 Let's explore Revit API Docs to understand how to protect our scripts from errors.
Protect scripts against changes
There are 2 options to protect your scripts from changes.
You can limit your tools to certain Revit versions. They won't be available in other Revit versions.
We can simply use meta tags in pyRevit for that.
Or we can write different code blocks for different Revit versions.
We can get Revit version using VersionNumber property from Application.
How to detect Changes in Revit API?
💡 Usually I test my tools in multiple Revit versions, so if I get an error I know where to look. But we can also explore Revit API Docs to find these differences.
When you select any class/method/property in Revit API Docs, you might have noticed that Revit years get colored line under them.
Red - Missing
Yellow - Changed
Gray - Unchanged
Cyan - Current
Gap Year
Usually when there are changes to Revit API, they leave us a Gap year, where both old and new versions are available.
That gives us some time to take changes into an account, so our tools don't start crashing right away.
For Example:
If you want to create a floor with Revit API there are 2 methods before and after 2022.
Before 2022: doc.NewFloor()
After 2022 : Floor.Create()
Obsolete Members
When you explore Revit API and selected method is in the gap year, it will be marked Obsolete.
You will also notice Obsolete Attribute if you look into Syntax of this method.