Override graphics by element for selected view

Hi All,

I’ve adapted the below python script from Element color override in viewS and I would like to feed in an OverrideGraphicSettings object from the OOTB node OverrideGraphicSettings.ByProperties

My problem is that the object output by this node is of Revit.Filter.OverrideGraphicSettings type and method used in my python script, SetElementOverrides, calls for an Autodesk.Revit.DB.OverrideGraphicSettings object.

Is it possible to use the OOTB node by tweaking my script to cast the first object as the second type?

This is the set up for this process:

The error that I return from running the script as above is:
image image

Thanks for reading

Hi @stefan.c,

Have you tried to Unwrap() your OGS input?

Hi @MartinSpence,

Thanks for your response.

Making this change gives me the same error message:
image

Ah yes, I just noticed the Revit.Filter.OverridesGraphicsSettings output.

I’m not familier with a way to change this to the OverridesGraphicsSettings. You may need to create this within the python script.

As far as I know, UnwrapElement will only work for actual Elements, however OverrideGraphicSettings is not a subclass of Element. There is a similar method called ToRevitType(), but this is only used for geometry conversion. It looks like your only option is to construct the OverrideGraphicSettings manually. Note that the available methods have changed for Revit 2019 and 2020 (with the addition of foreground and background).

I struggled with this issue a while back, and instead resorted to creating the OverrideGraphicSettings within the Python code, as @cgartland suggests

# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

# Import Element wrapper extension methods
import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *    

items = UnwrapElement(IN[0])
view = UnwrapElement(IN[1])
fillColour = UnwrapElement(IN[2])
lineColour = UnwrapElement(IN[3])
pattern = UnwrapElement(IN[4])

ogs = OverrideGraphicSettings()
ogs.SetProjectionFillColor(Color(fillColour.Red, fillColour.Green, fillColour.Blue))
ogs.SetProjectionLineColor(Color(lineColour.Red, lineColour.Green, lineColour.Blue))
ogs.SetProjectionFillPatternId(pattern.Id)
TransactionManager.Instance.EnsureInTransaction(doc)
for i in items:
    view.SetElementOverrides(i.Id, ogs)
TransactionManager.Instance.TransactionTaskDone()

image

2 Likes

I agree with @Thomas_Corrie solution though i would suggest you add a revit version checker to switch between what thomas has put and the new “BackGround” and “Foreground” version of the methods which you can find here(with a example below).

https://www.revitapidocs.com/2019/bd467fbb-a9da-7cf1-1ef5-f0f3568db0ac.htm

Note:Obsolete means they should be avoid from that version of revit on wards as they will be deleted out at some point.

Example:
image

3 Likes

@Brendan_Cassidy good point

Thanks all for your responses.

I created a separate python node to output an OGS of the correct type as suggested by @cgartland and based on @Thomas_Corrie’s suggestion:

I’m in 2017 for legacy project reasons but will roll in @Brendan_Cassidy’s suggestion when I move to 2019

Much appreciated

2 Likes