I’m trying to override element color in a view by a parameter value, I’m getting no errors but the color is not changing. This code probably has some extra bits because it is just for testing before I copy code over to a permanent tool later.
# Imports
# import pyRevit
from pyrevit import DB, revit, script, forms, HOST_APP
# Specific Imports
from Autodesk.Revit.DB import (FilteredElementCollector, View, Categories, Category, Element, CategoryType, Viewport,
BuiltInCategory, SharedParameterElement, Color, Transaction, OverrideGraphicSettings)
from Autodesk.Revit.UI import UIDocument
from Autodesk.Revit.ApplicationServices import Application
from itertools import izip_longest
import System
# ################################################################################
# Debug toggles
globalDebug = True
disabledScript = False
def dprint(*printItems):
if globalDebug:
for pI in printItems:
print(pI)
# Clicky
output = script.get_output()
# Spaces
spaces = " "
# Doc
doc = __revit__.ActiveUIDocument.Document
# Current View
cView = doc.ActiveView
acctive_view = HOST_APP.active_view
# Revit Version
versionValue = HOST_APP.version
####################################################################################################
####################################################################################################
# Color Code Sound Systems
####################################################################################################
####################################################################################################
speaker_collections = (FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_CommunicationDevices)
.WhereElementIsNotElementType().ToElements())
####################################################################################################
# Class
class SpeakerInfo:
def __init__(self, speaker_instance, system):
self.speaker_instance = speaker_instance
self.system = system
class SystemInfo:
def __init__(self, system, system_color):
self.system = system
self.system_color = system_color
####################################################################################################
# Get speakers and create list
speakers = []
for sC in speaker_collections:
dprint(sC.Name)
if sC.LookupParameter("Tech_SpeakerSystem") is None:
pass
else:
value = sC.LookupParameter("Tech_SpeakerSystem").AsString()
speakers.append(SpeakerInfo(sC, value))
# Speaker check for debug testing
dprint("___________________Speaker Check________________________")
for s in speakers:
dprint(s.speaker_instance.Name)
dprint(s.system)
dprint("___________")
####################################################################################################
# Get systems and create list
# Pastel Color List
color_list = [Color(255, 204, 153),
Color(255, 255, 153),
Color(204, 255, 153),
Color(153, 255, 153),
Color(153, 255, 204),
Color(153, 255, 255),
Color(153, 204, 255),
Color(153, 153, 255),
Color(204, 153, 255),
Color(255, 153, 255),
Color(255, 153, 204)]
systems = []
systems.append(SystemInfo("", Color(255, 0, 0)))
color_index = 0
for s in speakers:
if s.system in [x.system for x in systems]:
pass
else:
systems.append(SystemInfo(s.system, color_list[color_index]))
color_index += 1
dprint("___________________System Check________________________")
for s in systems:
dprint(s.system)
dprint(s.system_color)
with revit.Transaction("pyRevit - Speaker System Colors"):
for sp in speakers:
ogs = OverrideGraphicSettings()
ogs.SetProjectionLineColor([i.system_color for i in systems if i.system == sp.system][0])
acctive_view.SetElementOverrides(sp.speaker_instance.Id, ogs)
forms.alert("Colors added to speakers by system.")