LearnRevitAPI
![](https://framerusercontent.com/images/zMFB840Y52OLteloUT4BRuogE.png)
![](https://framerusercontent.com/images/U9zjOvD4k3m6cIJd5bOiu960DeI.png)
Feb 26, 2023
pyRevit Forms
![](https://framerusercontent.com/images/Sd5FTaxiqzG7oeH1ykV6yypUzXo.png?scale-down-to=512)
It’s often necessary to get user input in our tools. But creating custom forms with WPF is not beginner friendly. It has very steep learning curve so be prepared to translate a lot of C#.
However, there is an alternative that comes shipped with pyRevit and I want to show you how simple it is to use pre-made forms with pyRevit.
💡 It’s already well documented in pyRevit Dev Docs in Effective Inputs, but I want to shine some light on it, so you know where to look and how to use it.
👀 So let's look into forms and how easy it is to use them.
1️⃣ Alert
⚠️ Alerts are one of the most commonly used inputs in pyRevit. They are a simple yet effective way to get user input or stop execution of a tool with an alert message.
📃 Alerts can be used to ask Yes/No questions, ask a user to select from a list of options, or simply provide a message to the user with an option to exit scrip execution.
![](https://framerusercontent.com/images/JSJae7aAu8LMmYEOBpke5tmMXiQ.png)
👆 Here is doc string from forms.alert with all available arguments.
Don't get scared! You don't need to use all of them. In most cases I only use msg, title, exitscript and leave all the rest to default values.
Below you will find a few examples on how to use them.
⚠️ Alert + Exitscript
![](https://framerusercontent.com/images/2Iwwm6FohyKOIJ9bYce2om9QtrM.png)
![](https://framerusercontent.com/images/S4AYfeEaIYsWN9DZAiRT2BdA.png)
✅ Yes/No
![](https://framerusercontent.com/images/vYhyQ5k7LW4LJIUWvZ2YyaZjuFk.png)
![](https://framerusercontent.com/images/sBbBVEq8fDSS4sICtlaky1rps4.png)
⏹️Custom Buttons
![](https://framerusercontent.com/images/mFYDkvBmlGrXJaeegLsap3c35yo.png)
![](https://framerusercontent.com/images/UPjxpOhdrwIRLMnzm99Jsp5lSA.png)
2️⃣ WarningBar
⚠️ Warning Bars are a great way indicate to a user that he is supposed to do something.
For example I love using them when I need user to pick some elements. By using Warning Bar you will see an obvious yellow bar on the top with instructions what to do.
![](https://framerusercontent.com/images/mXcUlH84P3M26PBSgZkFQ8Cwl3w.png)
![](https://framerusercontent.com/images/mFE4n9a6aiGsswKr4O9P4dCvm4.png)
3️⃣ Pick File/Path
📁 Once in a while your scripts will need to read or write to a specific file or a folder. It’s not complicated to get it with os library in python, but this function in pyRevit is great.
👀 You will see a doc string with all available arguments if you want to dive deeper, but you can keep it simple as I did in my examples below.
![](https://framerusercontent.com/images/JSJae7aAu8LMmYEOBpke5tmMXiQ.png)
📂 Pick File/File
![](https://framerusercontent.com/images/M8MVzHnet1xImpEGyhyLMP117rI.png)
![](https://framerusercontent.com/images/ixKYR4uOFd1JOjwjkpT7NagzaG0.png)
4️⃣ Select Forms
📋pyRevit has a plenty of forms that will give you a list to choose desired elements such as:
Views, Sheets, ViewTemplates, Legends, Revisions, TitleBlocks...
✅ These are really useful and simple to use. With just one line you can create a form with a list of elements for user to choose from.
👇 There are many forms available and you can extend them even more with filterfunc if necessary. I have combined multiple examples into single code, so choose only what you need.
![](https://framerusercontent.com/images/dlmAXIgqzacSk3hxewVyUWgoqo.png)
![](https://framerusercontent.com/images/A4LTRMmwtBixBMrNjJJBxc5gxE.png)
![](https://framerusercontent.com/images/B8iyGcBHiiaEhAc9TcsnvkHPow.png)
5️⃣ Select From List
📃 The SelectFromList input allows the user to select one or more items from a list of options. It's exactly the same form as I show above, but you have more control over what you are showing to user.
There are different ways to use it, but I will show you 2 methods how I used it.
Select From List of Elements
🗃️ If you have a list of elements and you know that you can get names with just a property, you can provide name of that property in name_attr argument.
📰 That will work fine for many elements, however you will get an error if you try to get a .Name of any Type. But, don't worry, I will show you how to use it with dict where we can easily control Names and Elements.
![](https://framerusercontent.com/images/V02jSGo1S4uq3IgVBsZ7mY6eE.png)
![](https://framerusercontent.com/images/BegKjRKGx4nM7n37YrcrHbLfBFo.png)
Select From Dict
❌ Once you start using SelectFromList you will notice that you can't get all attributes. It only allows attributes that can get value as a property. (e.g. level.Name)
✅ But Don't Worry! We can create custom dictionary where keys will be visible names of elements in the form, and values are going to be returned elements.
![](https://framerusercontent.com/images/UUUvjrqSPAH3VuduLHRh2nOzRg.png)
![](https://framerusercontent.com/images/oR22FGl6SGdnW2F1rOn6ngM2Q.png)
6️⃣ Text Input
TextForm is another very simple form. It allows users to enter text into a dialog box that can be used in the code. This is useful for scripts that require the user to enter a certain value or text string.
![](https://framerusercontent.com/images/gxtZxMgHUB8mizHswEjsx7OC4hM.png)
![](https://framerusercontent.com/images/lM00oXT7Tiyx2VbdmWVXksaLUGo.png)
7️⃣ Conditions
🎭 Lastly, we can check conditions before running our script. It's often necessary to be in a certain ViewType or have selection in Revit for the script to run successfully. This is useful for ensuring that a script is only executed if certain conditions are met.
![](https://framerusercontent.com/images/rClej3KTjdlFlvnHFHxMxYtIU.png)
![](https://framerusercontent.com/images/rBUNkwIv1DULyhMbhwJoWFWEM.png)
8️⃣ rpw - FlexForm
🎁 As a bonus I want to mention FlexForm from rpw.
The rpw FlexForm is a powerful tool for creating custom forms in Revit and it is available in pyRevit by default!
✅ It allows users to create a custom form with multiple inputs, such as text boxes, dropdowns, checkboxes, and more. We can combine as many of them as we want and have a form with multiple input types in the order that we need.
![](https://framerusercontent.com/images/15eHYGxYFQYcgiGXu26LFMqukeU.png)
![](https://framerusercontent.com/images/I0FK5czL5jW6qevhr9YKqNn0.png)
I hope it helps you understand how to use built-in forms within pyRevit. It's not that complicated and you can always refer to original documentation
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)