LearnRevitAPI
Automate Shared Parameters in your Projects with Revit API
Dec 4, 2024
Load Shared Parameters
Importing parameters in Revit one by one is really boring and soul-draining. It's one of the tasks I hated the most...
So, being a pyRevit Hacker, I wrote a script to solve it. And I want to share the basics with you so you can do it as well.
Brainstorming
Before you start automating anything in Revit, just go through the process manually and try to break down all the steps you do.
Let's write all the manual steps we do:
Select Shared Parameter
Choose Type/Instance
Choose Parameter Group
Choose 'Values can very by group'
Choose Categories
I bet you already do these steps so fast, that you don't even notice it. Now we need to follow the same steps with code.
And let's start from the end and look at the documentation. You will find the following method to add parameters:
💡 This method will be obsolete in 2025, but it works in all previous versions. So I will only describe that.
You can see we only need 3 arguments, let's get them one by one.
1. Definition
Definitions are the blueprints of your parameters. And we can get ExternalDefinitions from SharedParameterFile.
Step 1: Select Shared Parameter
Here is a complete code snippet that will:
Open SharedParameterFile
Iterate through Groups and Definitions
Sort in a Dict
Create pyRevit.SelectFromList form to select
💡You can adjust the code to anything else if you want other logic on selecting parameters.
2. Binding
The next one is Binding. If you explore docs, you will notice that it's an abstract class and we need to use children classes:
InstanceBinding
TypeBinding
So we are creating option for this setting.
Step 2: Select ParameterBinding
When you look at how to create them, you will notice that we also need to create a CategorySet.
InstanceBinding Constructor (CategorySet)
TypeBinding Constructor (CategorySet)
So we are combining Category Selection and Instance/Type toggle. Here is a code:
There are 2 ways to get your categories and then you can insert them to your NewCategorySet:
Then we need to decide if we want Instance or Type Binding, and we also have 2 options to create this kind of binding:
💡 You just need to select one code line from this example.
3. Group
Lastly, we need to choose a ParamegerGroup.
Step 3: Select Parameter Group
It's very easy because we will use BuiltInParameterGroup Enumeration, so it already contains all possible values same as in Revit UI.
Put it all Together
Alright, we went through all the steps briefly, now let's just combine it into a single code snippet you could actually start using to automate this boring task with some python code.
Here is full python code:
And here is the end result in action:
Testimonial Highlight
Here is a recent LearnRevitAPI Testimonial.
Join Newsletter
📩 You will be added to Revit API Newsletter
Join Us!
which is already read by 7500+ people!