OverrideGraphicSettings

I am working on a node to override graphic settings in views, specifically aimed towards modifying view templates in bulk. I used the node from Genius Loci as well as some tutorial information from Eric Fritz to get where I am now.

I am getting an error I dont know what to do about now though.

This is the code I am using to pass the view templates to the node:

import clr
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')

# ------------------------------------------------------------Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 

#---------------------------------------------------------------------------------Loads Revit API and APIUI
#Adding reference to Revit's API DLLs
clr.AddReference("RevitAPI")

#------------------------------------------------------------------------------Loads the Autodesk namespace
import Autodesk
#Loading Revit's API classes
from Autodesk.Revit.DB import FilteredElementCollector, View, Category, BuiltInCategory

#CODE_______________________________________________________________________________________________________


#Define Variables

doc = DocumentManager.Instance.CurrentDBDocument

#Filtered Element Creator________________________________
all_views = FilteredElementCollector(doc)\
                .OfCategory(BuiltInCategory\
                .OST_Views)\
                .WhereElementIsNotElementType()\
                .ToElements()
               
view_templates = [v for v in all_views if v.IsTemplate and v.ViewType.ToString() != "ThreeD"]

OUT = view_templates

And here is my code for the Overrides:

import clr

# Import the Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
version = int(app.VersionNumber)


def tolist(obj1):
	if hasattr(obj1, "__iter__"):
		return obj1
	else:
		return [obj1]


def ConvertColor(e):
	return Autodesk.Revit.DB.Color(e.Red, e.Green, e.Blue)


views = tolist(IN[0])
cat = IN[1]
proj_Line_Pats = UnwrapElement(IN[2])
proj_Line_Colors = IN[3]
proj_Line_Weights = IN[4]

surface_Fore_Pats = UnwrapElement(IN[5])
surface_Fore_Colors = IN[6]

cut_Line_Pats = UnwrapElement(IN[7])
cut_Line_Colors = IN[8]
cut_Line_Weights = IN[9]

cut_Fore_Pats = UnwrapElement(IN[10])
cut_Fore_Pats_colors = IN[11]

transparencies = IN[12]
halftones = IN[13]
vis = IN[14]

# Create the OverridesGraphicsSettings
ogs = OverrideGraphicSettings()
#-----------------------------------------------------------------------------------------------------------------------
if proj_Line_Pats == None:
	pass
else:
	ogs.SetProjectionLinePatternId(proj_Line_Pats.Id)
	
if proj_Line_Colors == None:
	pass
else:
	ogs.SetProjectionLineColor(ConvertColor(proj_Line_Colors))
	
if proj_Line_Weights == None:
	pass
else:
	ogs.SetProjectionLineWeight(proj_Line_Weights)

#-----------------------------------------------------------------------------------------------------------------------
if surface_Fore_Pats == None:
	pass
else:
	ogs.SetSurfaceForegroundPatternId(surface_Fore_Pats.Id)
	ogs.SetSurfaceForegroundPatternVisible(True)

if surface_Fore_Colors == None:
	pass
else:
	ogs.SetSurfaceForegroundPatternColor(ConvertColor(surface_Fore_Colors))
#-----------------------------------------------------------------------------------------------------------------------
if cut_Line_Pats == None:
	pass
else:
	ogs.SetCutLinePatternId(cut_Line_Pats.Id)

if cut_Line_Colors == None:
	pass
else:
	ogs.SetCutLineColor(ConvertColor(cut_Line_Colors))

if cut_Line_Weights == None:
	pass
else:
	ogs.SetCutLineWeight(cut_Line_Weights)
#-----------------------------------------------------------------------------------------------------------------------
if cut_Fore_Pats == None:
	pass
else:
	ogs.SetCutForegroundPatternId(cut_Fore_Pats.Id)
	ogs.SetCutForegroundPatternVisible(True)

if cut_Fore_Pats_colors == None:
	pass
else:
	ogs.SetCutForegroundPatternColor(ConvertColor(cut_Fore_Pats_colors))
#-----------------------------------------------------------------------------------------------------------------------
if transparencies == None:
	pass
else:
	ogs.SetSurfaceTransparency(transparencies)

if halftones == None:
	pass
else:
	ogs.SetHalftone(halftones)

views_out = []

# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

"""if vis == None:
	for v in views:
		for c in cats:
			v.SetCategoryOverrides(c, ogs)
			views_out.append(v)

else:
	for v in views:
		for c in cats:
			v.SetCategoryOverrides(c, ogs)
			v.SetCategoryHidden(c)
			views_out.append(v)
"""

for v in views:
	v.SetCategoryOverrides(cat, ogs)
	views_out.append(v)

# End Transaction
TransactionManager.Instance.TransactionTaskDone()

OUT = ogs

Here is the Dynamo Graph I am using to develop it as well:

OverrideGraphicsDev.dyn (24.2 KB)

Any help is greatly appreciated!

as a quick note, I know that there are other packages that can achieve the same, however the way my graph is, I want the flexibility to really control how the iteration is handled. So once I get this working I plan to build it to specifically handle multiple categories and multiple views with a runme.

Hi @J_Sanford,
Unfortunately I don’t believe that the View Templates in Revit have an working API in python - there are the API methods View.CreateViewTemplate() and View.GetTemplateParameterIds() but I have not been able to find them when I try to view the function methods and variables via the Python dir(View) function - It does reveal undocumented API methods though (see below). Is it possible to set via the (template) View parameters?
This functionality has been a bit of an ongoing discussion on the Autodesk Revit API Forum for a long time…
image

Interesting, so its specific to Python? I have a graph using Rhythm nodes that has worked for modifying my view tempaltes in bulk for some time, view templates are just views and can be modified like views. Ive used it for some time to modify my revit template view templates, unfortunately the problem with the 24 upgrade sent me down this rabbit hole. View templates are just views actually, and like views they can have overrides applied to them. Maybe I need to use a different override instead?

For example here are the methods/parameters exposed for View Class filtered for ‘Template’
image

This from a view and view template
image

I have been able to dig around but it takes time
OUT = [System.Enum.GetName(BuiltInParameter, id.IntegerValue) for id in View.GetTemplateParameterIds(doc.ActiveView)]
Result - No template applied
image

Once a template is applied there is more info
image

how do you get this data? Its my understanding thats view templates themselves are views, but I want to run a report like this on view templates and see what I find

Hi,
you forgot several conversions, here the fixed code


import clr
import sys
import System
# Import the Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
version = int(app.VersionNumber)


def tolist(obj1):
	if hasattr(obj1, "__iter__"):
		return obj1
	else:
		return [obj1]


def ConvertColor(e):
	return Autodesk.Revit.DB.Color(e.Red, e.Green, e.Blue)


views = tolist(UnwrapElement(IN[0]))
cat = System.Enum.ToObject(DB.BuiltInCategory, IN[1].Id)
proj_Line_Pats = UnwrapElement(IN[2])
proj_Line_Colors = IN[3]
proj_Line_Weights = IN[4]

surface_Fore_Pats = UnwrapElement(IN[5])
surface_Fore_Colors = IN[6]

cut_Line_Pats = UnwrapElement(IN[7])
cut_Line_Colors = IN[8]
cut_Line_Weights = IN[9]

cut_Fore_Pats = UnwrapElement(IN[10])
cut_Fore_Pats_colors = IN[11]

transparencies = IN[12]
halftones = IN[13]
vis = IN[14]

# Create the OverridesGraphicsSettings
ogs = DB.OverrideGraphicSettings()
#-----------------------------------------------------------------------------------------------------------------------
if proj_Line_Pats == None:
	pass
else:
	ogs.SetProjectionLinePatternId(proj_Line_Pats.Id)
	
if proj_Line_Colors == None:
	pass
else:
	ogs.SetProjectionLineColor(ConvertColor(proj_Line_Colors))
	
if proj_Line_Weights == None:
	pass
else:
	ogs.SetProjectionLineWeight(proj_Line_Weights)

#-----------------------------------------------------------------------------------------------------------------------
if surface_Fore_Pats == None:
	pass
else:
	ogs.SetSurfaceForegroundPatternId(surface_Fore_Pats.Id)
	ogs.SetSurfaceForegroundPatternVisible(True)

if surface_Fore_Colors == None:
	pass
else:
	ogs.SetSurfaceForegroundPatternColor(ConvertColor(surface_Fore_Colors))
#-----------------------------------------------------------------------------------------------------------------------
if cut_Line_Pats == None:
	pass
else:
	ogs.SetCutLinePatternId(cut_Line_Pats.Id)

if cut_Line_Colors == None:
	pass
else:
	ogs.SetCutLineColor(ConvertColor(cut_Line_Colors))

if cut_Line_Weights == None:
	pass
else:
	ogs.SetCutLineWeight(cut_Line_Weights)
#-----------------------------------------------------------------------------------------------------------------------
if cut_Fore_Pats == None:
	pass
else:
	ogs.SetCutForegroundPatternId(cut_Fore_Pats.Id)
	ogs.SetCutForegroundPatternVisible(True)

if cut_Fore_Pats_colors == None:
	pass
else:
	ogs.SetCutForegroundPatternColor(ConvertColor(cut_Fore_Pats_colors))
#-----------------------------------------------------------------------------------------------------------------------
if transparencies == None:
	pass
else:
	ogs.SetSurfaceTransparency(transparencies)

if halftones == None:
	pass
else:
	ogs.SetHalftone(halftones)

views_out = []

# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

"""if vis == None:
	for v in views:
		for c in cats:
			v.SetCategoryOverrides(c, ogs)
			views_out.append(v)

else:
	for v in views:
		for c in cats:
			v.SetCategoryOverrides(c, ogs)
			v.SetCategoryHidden(c)
			views_out.append(v)
"""

for v in views:
	if v.AreGraphicsOverridesAllowed():
		v.SetCategoryOverrides(ElementId(cat), ogs)
		views_out.append(v)

# End Transaction
TransactionManager.Instance.TransactionTaskDone()

OUT = ogs, cat
3 Likes

Works great! so looking at this it seems I wasnt unwrapping my views and wasnt handling my categories correctly?

Yes

1 Like

thanks for the help! really appreciated :slight_smile: I have it working well now and added some code to handle multiple categories as well.