__title__ = "Get/Create FilledRegion"
__author__ = "Erik Frits"
from Autodesk.Revit.DB import *
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'
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"""
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)
return FilteredElementCollector(doc).OfClass(FilledRegionType).WherePasses(my_filter).FirstElement()
def create_RegionType(name, color, masking = False, lineweight = 1):
"""Create FilledRegionType with Solid Pattern."""
random_filled_region = FilteredElementCollector(doc).OfClass(FilledRegionType).FirstElement()
new_region = random_filled_region.Duplicate(name)
new_region.BackgroundPatternId = ElementId(-1)
new_region.ForegroundPatternId = solid_pattern.Id
new_region.BackgroundPatternColor = color
new_region.ForegroundPatternColor = color
new_region.IsMasking = masking
new_region.LineWeight = lineweight
return new_region
region_A = get_filled_region(region_name_A)
region_B = get_filled_region(region_name_B)
with Transaction(doc,__title__) as t:
t.Start()
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(Element.Name.GetValue(region_A))
print(Element.Name.GetValue(region_B))