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.

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 7200+ people!

Last Chance To Claim LIFETIME ACCESS. [~40 Seats left]