Get Existing / Create New FilledRegionType

# -*- coding: utf-8 -*-
__title__   = "Get/Create FilledRegion"
__author__  = "Erik Frits"

# ╦╔╦╗╔═╗╔═╗╦═╗╔╦╗╔═╗
# ║║║║╠═╝║ ║╠╦╝ ║ ╚═╗
# ╩╩ ╩╩  ╚═╝╩╚═ ╩ ╚═╝ IMPORTS
# ==================================================
# Regular + Autodesk
from Autodesk.Revit.DB import *

# ╦  ╦╔═╗╦═╗╦╔═╗╔╗ ╦  ╔═╗╔═╗
# ╚╗╔╝╠═╣╠╦╝║╠═╣╠╩╗║  ║╣ ╚═╗
#  ╚╝ ╩ ╩╩╚═╩╩ ╩╚═╝╩═╝╚═╝╚═╝ VARIABLES
# ==================================================
doc   = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
app   = __revit__.Application
rvt_year = int(app.VersionNumber)

region_name_A = 'New Region A'
region_name_B = 'New Region B'

# Get Solid Pattern
all_patterns       = FilteredElementCollector(doc).OfClass(FillPatternElement).ToElements()
all_solid_patterns = [pat for pat in all_patterns if pat.GetFillPattern().IsSolidFill]
solid_pattern      = all_solid_patterns[0]


# ╔═╗╦ ╦╔╗╔╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
# ╠╣ ║ ║║║║║   ║ ║║ ║║║║╚═╗
# ╚  ╚═╝╝╚╝╚═╝ ╩ ╩╚═╝╝╚╝╚═╝
def get_filled_region(filled_region_name):
    """Function to get FireWall Types based on FamilyName"""
    # Create Filter
    pvp         = ParameterValueProvider(ElementId(BuiltInParameter.ALL_MODEL_TYPE_NAME))
    condition   = FilterStringEquals()
    fRule =     FilterStringRule(pvp, condition, filled_region_name, True) if rvt_year < 2022 \
             else FilterStringRule(pvp, condition, filled_region_name)
    my_filter   = ElementParameterFilter(fRule)

    # Get Types
    return FilteredElementCollector(doc).OfClass(FilledRegionType).WherePasses(my_filter).FirstElement()


def create_RegionType(name, color, masking = False, lineweight = 1):
    #type: (str, Color, bool, int) -> FilledRegionType
    """Create FilledRegionType with Solid Pattern."""
    random_filled_region = FilteredElementCollector(doc).OfClass(FilledRegionType).FirstElement()
    new_region           = random_filled_region.Duplicate(name)

    # Set Solid Pattern
    new_region.BackgroundPatternId = ElementId(-1)
    new_region.ForegroundPatternId = solid_pattern.Id

    # Set Colour
    new_region.BackgroundPatternColor = color
    new_region.ForegroundPatternColor = color

    # Masking
    new_region.IsMasking = masking

    # LineWeight
    new_region.LineWeight = lineweight

    return new_region


# ╔╦╗╔═╗╦╔╗╔
# ║║║╠═╣║║║║
# ╩ ╩╩ ╩╩╝╚╝ MAIN
# ==================================================

# Try to get existing FilledRegions
region_A = get_filled_region(region_name_A)
region_B = get_filled_region(region_name_B)

with Transaction(doc,__title__) as t:
    t.Start()
    # Create new if does not exist
    if not region_A: region_A = create_RegionType(name = region_name_A, color = Color(255,128,128))
    if not region_B: region_B = create_RegionType(name = region_name_B, color = Color(128,128,255))
    t.Commit()

# Print Names of Regions:
print(Element.Name.GetValue(region_A))
print(Element.Name.GetValue(region_B))

⌨️ Happy Coding!
Erik Frits