LearnRevitAPI
📊How to Create Custom pyRevit Form with Multiple Buttons?
Jan 23, 2025
UI Forms in pyRevit
Creating custom UI is quite an advanced topic.
But there is a easy way to with pyRevit. We can use FlexForms from rpw module, and it's already included in pyRevit by default. it's the easiest way to create custom UI forms.
Also I just got a question: "How to create multiple buttons in FlexForm", so I will share the answer to this one as well with you.
rpw FlexForm
FlexForm is a custom class that can create UI forms.
The best way to learn about FlexForm is to try it out yourself. So I will provide you 2 examples and you can try them on your own.
And to be honest, the code is quite self explanatory. You can Copy-Paste the code and then compare how your UI form looks to the code. And it will make a lot of sense.
I will provide you 2 examples.
Simple FlexForm
Here is the first code example to create a very simple UI form.
This is how it will look like:
In genral you can see that we import a bunch of classes from rpw.ui.forms.
Then, we create components that will be stacked on top of each other, and we can use it to create our FlexForm.
Once you are done you can get values from your form with form.values property that will return you a dictionary.
When you create your components you will notice that we provide 2 arguments where user needs to make some input. The first one is the key that will be used for dictionary, so you can get this data out.
FlexForm with multiple Buttons
Alright, how about creating multiple buttons for different purposes? That's also possible, but might be tricky first time.
You just need to understand how Events work in programming. In short, you can execute code when an event occurs. In this case button click.
So we can create another button and in rpw.ui.Button there is a parameter called on_click which can assign python function to the button click.
It's fairly simple to use, however there are a few things to keep in mind about events.
Function Arguments: Whenever you subscribe to an event, you'll need to have 2 arguments in a function: (sender, event_args).
Sender - Refers to the UI object itself (button in this case).
EventArgs - Refers to the event that was triggered (click in our case).
⌨️ Below is an example code snippet:
💡Make sure you don't use parentheses when you assign a function to the on_click argument!
And then you get this form, where you will trigger functions with simple print statements on Button 1/2 and Submit will close the form as usual.
Need more control?
FlexForms are great, but they are also limited. You can stack any number of simple inputs, however you won't be able to create more advanced UI forms with custom layouts.
If that's something you want to learn, you need to learn about WPF Framework. It has a steep learning curve, but it's absolutely the best way to create a custom UI forms that looks and functions exactly how you want. You literally can create anything with it.
Here is my latest UI Form with drag and drop functionality:
How to learn WPF for pyRevit?
There are not many resources about WPF for python, so it makes it a challenge to get started.
However, since that's what I use in many of my forms people asked me many times to share how I do that. And that's what I did a few months ago.
I've created a full in-depth course about WPF for pyRevit users . I will show you step by step how to create custom good-looking forms for pyRevit tools.
You can learn more about it here
At the moment it's available only as a bonus to all my course members. They all got it for FREE. And if you join LearnRevitAPI you will also get it as a bonus.
However, I will make it for sale as a separate course in the future. Let me know if that's something you would want to see sooner.
Join Newsletter
📩 You will be added to Revit API Newsletter
Join Us!
which is already read by 7500+ people!
The Bundle Price Increases in
Join Today with 30% OFF.