Multiple override graphic settings in one transaction

Hi,

Im fairly knew to python and the revit api.

I’m attempting to set an object transparent and halftone. The code below only sets the element to halftone. But if i comment out the halftone, it will set the element to transparent… Im not sure why it wont set both.

import clr

clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI') 
from Autodesk.Revit.DB import * 
from Autodesk.Revit.UI import *

app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
selection = [doc.GetElement(x) for x in uidoc.Selection.GetElementIds()]

t = Transaction(doc, 'transparenthalftone')
t.Start()

for i in selection:
    doc.ActiveView.SetElementOverrides((i.Id), 
    OverrideGraphicSettings().SetSurfaceTransparency(100)
	OverrideGraphicSettings().SetHalftone(True))
t.Commit()

__window__.Close()

Hi,
you need to create a instance of graphics overrides and then just use another overload of SetElementOverrides which takes elementId and OverrideGraphicSettings as inputs.

sth like

ogs = OverrideGraphicSettings()
ogs.SetProjectionFillColor(R,G,B)
ogs.SetProjectionLineColor(R,G,B)
ogs.SetProjectionFillPatternId(pattern.Id)
ogs.SetSurfaceTransparency(100)
ogs.SetHalftone(True)

t = Transaction(doc, 'transparenthalftone')
t.Start()
for i in selection:
    doc.ActiveView.SetElementOverrides(i.Id, ogs)
t.Commit()

In your code → only the last override would be applied

3 Likes

Thanks Tomasz! that worked.