LearnRevitAPI
May 23, 2023
Automate Shared Parameters
🤯Tired of manually adding Shared Parameters in Revit one by one?
✅ I've got an exciting solution for you!
Learn how to automate the process using Revit API and Python.
💡 Let's learn how to work with Shared Parameters in Revit API.
1️⃣ Shared Parameters File
🔎 First things first, let's locate the SharedParametersFile, a crucial step in reading, creating, and importing Shared Parameters.
✌️ There are two approaches we can take. We can either get the currently used SharedParametersFile in Revit or set a specific file path ourselves.
👇 Let's explore these options.
💡 I prefer to always set the path, so I know exactly what SharedParameterFile I am working with.
2️⃣ Read Shared Parameters
📄 Once you have obtained your SharedParameterFile, the process of reading ParameterGroups and ExternalDefinitions (Parameters) becomes quite straightforward.
👇 Here is a code snippet that allows you to print out all the ParameterGroups and their corresponding ExternalDefinitions inside them:
💡 You can explore these classes further in the Revit API Docs:
DefinitionGroup class - Parameter Groups in Shared File.
ExternalDefinition class - Parameters in Shared File
👇 If you want to get specific ParameterGroup or a Parameter by Name then you can use the following snippet.
3️⃣ CategorySet
👀 We know how to read parameters, but before we start adding them to our Revit project we need to prepare a CategorySet.
🗃️ Creating a CategorySet is not complicated and it's all about deciding what categories do we need.
Typically, when manually adding parameters, we scroll through this list of categories and select the desired ones.
However, when we code we have to create a CategorySet and add BuiltInCategories that we want.
Here is a code snippet that demonstrates how to create a new CategorySet and add the "Views" and "Sheets" categories to it:
💡 You can take it a step further and create a UI to select these categories.
4️⃣ Add Shared Parameters
Once we have a clear understanding of how to read the Shared Parameter File and create a Category Set, we can proceed with adding Shared Parameters to our Revit projects.
Let's continue building upon the previous code snippet by adding all Shared Parameters that have 'PS_' in their names.
💡 Adding Shared Parameters involves two steps:
Create a NewInstanceBinding to define the binding of the Shared Parameter.
Insert the NewInstanceBinding into doc.ParameterBindings to associate it with the Revit document.
5️⃣ Create New Parameter
Lastly, if you want to actually create new ParameterGroups or Parameters in your SharedParameterFile, you can use the following Snippet.
💡 Notice that there are differences in Revit API 22-23, so we also have to check Revit's version before creating ExternalDefinitionCreationOptions.
❌ Adding lots of SharedParameters can become frustrating, especially on multiple projects.
✨ So I hope after reading this newsletter you won't hate working with Shared Parameter as much and even start to enjoy the process!
Join Newsletter
📩 You will be added to Revit API Newsletter
Join Us!
which is already read by 7400+ people!
◼️BLACK FRIDAY DEAL 20% OFF. Ends in: