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:

  1. Create a NewInstanceBinding to define the binding of the Shared Parameter.

  2. 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!

Enjoyed Newsletter?

Leave a Testimonial Here.

⌨️ Happy Coding!
Erik Frits

Join Newsletter

πŸ“© You will be added to Revit API Newsletter

Join Us!

which is already read by 6700+ people!