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.

I was hoping to get some feedback for graphic settings. I have a similar task. I want to be able to make all the grid lines/bubbles in the all the views not half toned. This is what i have but it doesn’t take. It runs through with no issues but my grids are still haftone. any ideas where it is failing to uncheck the halftone in the visibility graphics?
For now i am trying to make it work for the active view and if that works, then i can swap it for all the views.

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

app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument

active_view = uidoc.ActiveView

# Check if the active view is a valid view
if active_view is None or active_view.IsTemplate:
    TaskDialog.Show("Error", "No valid active view found.")
else:
    t = Transaction(doc, 'Modify Grid Halftone')
    t.Start()

    try:
        # Get all grid elements in the active view
        collector = FilteredElementCollector(doc, active_view.Id).OfCategory(BuiltInCategory.OST_Grids)
        grids = [grid for grid in collector.ToElements()]

        for grid in grids:
            # Modify halftone setting for grid
            overrides = active_view.GetElementOverrides(grid.Id)
            overrides.SetHalftone(False)

        # Commit the transaction
        t.Commit()
        TaskDialog.Show("Success", "Halftone setting for grid annotations updated.")
    except Exception as e:
        # Roll back the transaction if an error occurs
        t.RollBack()
        TaskDialog.Show("Error", "An error occurred: {}".format(e))```
from pyrevit import revit, DB, HOST_APP, forms

doc = revit.doc
active_view = HOST_APP.active_view

with revit.Transaction("reset halftone for grids"):
    grids = DB.FilteredElementCollector(doc, active_view.Id).OfCategory(DB.BuiltInCategory.OST_Grids).ToElements()
    print(len(grids))
    for grid in grids:
        ogs = DB.OverrideGraphicSettings()
        ogs.SetHalftone(False)
        active_view.SetElementOverrides(grid.Id, ogs)
    forms.alert("Halftone settings for grids annotations reset suceeded.")

I simplified it, the Graphics overrides are per view, so you set the element overrides of the view for a specific element:

  1. declare OG
  2. set the property you want to change in this OG bucket
  3. apply it to the view with the SetElementOverrides method with two arguments: element.Id of the element you want to change the graphics, your OG bucket

Jean, it did not seem to apply the reset. the grids/bubbles remained as halftone.
Could this be my model perhaps?
image

It works in my very simple project.
Make a new bare model with only grids and overrides per element as halftone
Element override or category override (VV/VG)? Or grids in a linked file (cannot be controled this way)? Or is a workset and all non active worksets are set to display halftone.

ohhh, i see now. It is element specific.
image

I failed to convey this message. I was referring to the halftone button in the Visibility Graphics Override
image

Did you find a solution?