pyRevit

Code
Library
Change Graphic Overrides of an Element in View
#โฌ๏ธ IMPORTS
from Autodesk.Revit.DB import *
#๐ฆ Variables
doc = __revit__.ActiveUIDocument.Document
view = doc.ActiveView
walls_in_view = FilteredElementCollector(doc, doc.ActiveView.Id) \
.OfCategory(BuiltInCategory.OST_Walls) \
.WhereElementIsNotElementType() \
.ToElements()
#๐จ COLORS
color_yellow = Color(255,255,0)
color_red = Color(255,0,0)
color_blue = Color(0,0,255)
#๐งฑ GET PATTERNS
all_patterns = FilteredElementCollector(doc).OfClass(FillPatternElement).ToElements()
solid_pattern = [i for i in all_patterns if i.GetFillPattern().IsSolidFill][0]
#ใฐ๏ธ LINES
line_patterns = FilteredElementCollector(doc).OfClass(LinePatternElement).ToElements()
random_line_pattern = line_patterns[0]
lineweight = 5
#โ๏ธ CREATE OVERRIDE SETTINGS
override_settings = OverrideGraphicSettings()
#โ๏ธ SURFACE FOREGROUND (PATTERN + COLOR)
override_settings.SetSurfaceForegroundPatternId(solid_pattern.Id)
override_settings.SetSurfaceForegroundPatternColor(color_yellow)
#โ๏ธ CUT FOREGROUND ( PATTERN + COLOR)
override_settings.SetCutForegroundPatternId(solid_pattern.Id)
override_settings.SetCutForegroundPatternColor(color_yellow)
#โ๏ธ PROJECTION LINES (Extra)
override_settings.SetProjectionLineColor(color_red)
override_settings.SetProjectionLinePatternId(random_line_pattern.Id)
override_settings.SetProjectionLineWeight(lineweight)
#โ๏ธ CUT LINES (Extra)
override_settings.SetCutLineColor(color_red)
override_settings.SetCutLinePatternId(random_line_pattern.Id)
override_settings.SetCutLineWeight(lineweight)
#โ๏ธ SET TRANSPARENCY
override_settings.SetSurfaceTransparency(50)
#๐ฏ MAIN
with Transaction(doc, 'Override Colours') as t:
t.Start()
#๐ OVERRIDE ELEMENT GRAPHICS IN ACTIVE VIEW
for wall in walls_in_view:
view.SetElementOverrides(wall.Id, override_settings)
t.Commit()
__author__ = '๐โโ๏ธ Erik Frits'
โจ๏ธ Happy Coding!
Erik Frits