def create_region(view, X, Y, region_width, region_height):
region_type_id = doc.GetDefaultElementTypeId(ElementTypeGroup.FilledRegionType)
points_0 = XYZ(X, Y, 0.0)
points_1 = XYZ(X+region_width, Y, 0.0)
points_2 = XYZ(X+region_width, Y-region_height, 0.0)
points_3 = XYZ(X, Y-region_height, 0.0)
points = [points_0, points_1, points_2, points_3, points_0]
list_boundary = List[CurveLoop]()
boundary = CurveLoop()
for n, point in enumerate(points):
if n == 4: break
p1, p2 = points[n], points[n + 1]
boundary.Append(Line.CreateBound(p1, p2))
list_boundary.Add(boundary)
filled_region = FilledRegion.Create(doc, region_type_id, view.Id, list_boundary)
return filled_region