Here’s an example of a Python script that overrides Tags by view. Keep in mind that list of Elements and list of Views have to match in length.
Here’s Python script:
# Copyright(c) 2019, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net
import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
def ConvertColor(e):
return Autodesk.Revit.DB.Color(e.Red, e.Green, e.Blue)
def OverrideColorPattern(e, c, f, view):
gSettings = OverrideGraphicSettings()
gSettings.SetProjectionLineColor(c)
gSettings.SetProjectionLinePatternId(UnwrapElement(f).Id)
UnwrapElement(view).SetElementOverrides(UnwrapElement(e).Id, gSettings)
return e
try:
errorReport = None
TransactionManager.Instance.EnsureInTransaction(doc)
c = ConvertColor(IN[1])
output = []
for i, j in zip(IN[0], IN[3]):
output.append(OverrideColorPattern(i, c, IN[2], j))
TransactionManager.Instance.TransactionTaskDone()
except:
import traceback
errorReport = traceback.format_exc()
if errorReport == None:
OUT = output
else:
OUT = errorReport
Obviously I just did lines because I was overriding tags, so they don’t have solid geometry, but for someone who wants to override walls, you might want to also add surfaces to the override routine. The API is referenced here:
https://apidocs.co/apps/revit/2020/bd467fbb-a9da-7cf1-1ef5-f0f3568db0ac.htm
It’s a different API for Revit 2020 which is what I am using for demonstration above. Keep in mind that some older methods available in 2017 or 2018 were removed in 2020.
Script:
2_colorByView.dyn (12.3 KB)
Cheers!