Feb 1, 2023
RevitAPI: Get/Create FilledRegionType
There is no method to create new FilledRegionType. But it does not mean we can not duplicate existing one and adjust its parameters. Read More if you want to Create new FilledRegionType.
If you are reading this, then you have a question in your mind:
How to create a new FilledRegionType in Revit API?
You might have noticed that there are no methods in Revit API Docs to do that.
However, it does not mean we can’t take existing one and duplicate it. Then you can change necessary properties, so it's indeed a new FilledRegionType.
So let me take you through all these steps to write a code to: Get Existing FilledRegionType or Create a new one if it doesn't exist.
👉 Get Existing FilledRegionType by Name
First, let's check if desired FilledRegionType already exists. This will help you avoid duplicates and unwanted errors in your projects.
Here is a code snippet to do that:
🆕 Duplicate existing FilledRegionType
If we can't find the FilledRegionType, let's make our own! Here’s how in a few simple steps:
Define desired Pattern, Colour, Lineweight and Masking settings.
Get existing FilledRegionType and Duplicate it
Change parameters as you need
I am going to walk you through these steps.
1️⃣ Get Solid Pattern
Let’s begin by getting the right pattern for our new FilledRegionType.
In my case I will look for Solid pattern, but you can write your own logic to get desired pattern.
2️⃣ Get random FilledRegionType and Duplicate
I am going to get a random FilledRegionTypes with FilteredElementCollector. Since we are going to change all settings it does not matter which one we take. However, it's important to provide unique new name.
💡 NB! You will get an error if you are trying to duplicate FilledRegionType with an existing new name, be aware of that!
Now we have our new FilledRegionType with desired name and we can start changing its settings.
3️⃣ Apply new Settings to FilledRegionType
The last step is to change settings, and it’s not complicated.
All these settings are readable and writable properties, so it’s going to be very easy to set new values.
✨ Final Code
Here is the final code for pyRevit's .pushbutton to Get or Create new FilledRegionType.