LearnRevitAPI
May 4, 2023
Create Custom UI
❓ I keep getting asked "how to create a Custom UI".
🤯 Unfortunately using WPF is not straigh-forward and might discourage a lot of people. But I found something interesting, worth sharing.
✅ There is package rpw, which is also included in pyRevit by default. And there is a class of FlexForm which is very easy to use, and you can customize how UI looks by combining components.
👇 So let's explore how to use rpw.forms.FlexForm
1️⃣ rpw Package
📦 The rpw package, also known as the Revit Python Wrapper, is an open-source library created by Gui Talarico.
It has a bunch of functions that you can use to code easier, but I want to share how to use FlexForm because it's very simple and you can create custom UI.
It will be limited, but should be enough for many people to start creating tools with a simple UI.
💡You can look at rpw documentation here 👉 Docs
2️⃣ Flex Form
The rpw.forms.FlexForm is a class within the rpw package that allows us to create simple, custom UIs by using a list of components.
Such as: Label, ComboBox, TextBox, TextBox as so on...
And the UI elements are displayed in the same order as the components list.
💪 It's a much simpler alternative to using WPF for beginners. Let's have a look at the code and resulting UI.
Once you create a list of components we need to provide it as an argument when we create our FlexForm.
And just with a few lines of code you will be able to create a UI like this
👇
Once user finishes writing/selecting values they are stored in a dictionary that we can get with form.values
And inside this dictionary keys are going to be values that you provided in your components, like this 👇
TextBox('dict_key_name', Text='Default Value')
💡 Then you can use these values to continue your script.
Flex Form Example
Here is another example how I create a simple UI form in my latest video to get some user input instead of hardcoding all the values.
👀 And that's what users will see on their screens.
Learn More
👀 Watch this YouTube video to learn more about creating custom UI
👇Click on the image
💡You will learn how to create a tool to randomize values across elements. But by the end I will show you how to use FlexForm from rpw to quickly make a simple custom UI.
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: