LearnRevitAPI
![](https://framerusercontent.com/images/zMFB840Y52OLteloUT4BRuogE.png)
![](https://framerusercontent.com/images/U9zjOvD4k3m6cIJd5bOiu960DeI.png)
May 23, 2023
Automate Shared Parameters
![](https://framerusercontent.com/images/Sd5FTaxiqzG7oeH1ykV6yypUzXo.png?scale-down-to=512)
π€―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.
![](https://framerusercontent.com/images/fLS6VSU6W5rhKBXxkJiej5XG4k.png)
π‘ 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:
![](https://framerusercontent.com/images/uYMiVTKw94uJ1Kms9A5RFTsJmM.png)
π‘ 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.
![](https://framerusercontent.com/images/t81xR77mud3MrFsEW1U6KyrEZg.png)
3οΈβ£ CategorySet
π We know how to read parameters, but before we start adding them to our Revit project we need to prepare a CategorySet.
![](https://framerusercontent.com/images/ROIQMPBppmQ0syM5fL3WzApasds.png)
ποΈ 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:
![](https://framerusercontent.com/images/uyZvFyxx2lLRr2OCAuyoyHUqZU.png)
π‘ 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.
![](https://framerusercontent.com/images/0Ac5rBcAw27f5NOo0hGBRaUeAo.png)
π‘ 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.
![](https://framerusercontent.com/images/de171lB6YTIQFDdi2fk5drZ5I.png)
π‘ 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 6700+ people!
![](https://framerusercontent.com/images/svHzzMLtnnRCxtCUwbgAm6CUeB8.jpg)
![](https://framerusercontent.com/images/Y44kwhY0i7q37LzXUjrlxeGUo.jpg)
![](https://framerusercontent.com/images/lqKYmh8rqwZwgY2C9MSQER6iBCI.jpg)
![](https://framerusercontent.com/images/SyGCvJ3dbHsJEyklWWBhweY.jpg)
![](https://framerusercontent.com/images/DwiaUdmQHs3FVdDH2PXwAr0Y.jpg)