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
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))```
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.