βΌοΈBLACK FRIDAY DEAL 20% OFF. Ends in:
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.
πIntroduction
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:
π‘Tip: You can change Evaluator to FilterStringContain instead of FilterStringEquals.
π 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
The next step is to get a random FilledRegionType and Duplicate it.
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.
Join Newsletter
π© You will be added to Revit API Newsletter
Join Us!
which is already read by 7400+ people!
Ready to become Revit Hero for your office? Learn Revit API!
Join this comprehensive course that will guide you step by step on how to create your dream tools for Revit that save time.