Temporarily overwriting element colour in a view

(For Revit 2020 API)

I’ve built up a QC tool that will enable elements (rooms in this case) to have a colour override assigned based on a defined parameter value

I have set the view to EnableTemporaryViewPropertiesMode() and assign HideElementTemporary to elements that do not meet the defined parameter value.

To assign a colour value to the rooms I’m using doc.ActiveView.SetElementOverrides(room_id, settings)
which commits itself to the view despite being in TemporaryViewPropertiesMode. I was under the impression that there was a way to set the ElementOverride temporarily, but maybe I’m missing something?

I’m pretty sure you cannot have temporary per-element overrides.

thanks, yeah that’s what I had thought, probably need to build an undo button :cowboy_hat_face:

or clear overrides button! :wink:

1 Like

like this ;p

from pyrevit import revit, DB, forms
try:
    selection = revit.get_selection()
    if len(selection)>0:
        with revit.Transaction('Clear graphical overrides'):
        	# erase overrides
            src_style = DB.OverrideGraphicSettings().Dispose()
            # get clear graphics without overrides
            src_style = DB.OverrideGraphicSettings()
            for element in selection:
                revit.active_view.SetElementOverrides(element.Id, src_style)
    else:
        forms.alert('You must select at least one element.', exitscript=True)
except:
    pass

this is what i ended up going with:

the overrides are for specifically rooms, as well as the colour overrides, there are certain objects temporarily hidden also so undoing that too

from pyrevit import revit
import Autodesk.Revit.DB as DB

logger = script.get_logger()



doc = __revit__.ActiveUIDocument.Document

rooms = (
    revit.DB.FilteredElementCollector(doc, doc.ActiveView.Id)
    .OfCategory(DB.BuiltInCategory.OST_Rooms)
    .WhereElementIsNotElementType()
    .ToElements()
)

with DB.Transaction(doc, "Undo Room Group QC Checker") as t:
    rooms = get_rooms_in_active_view(doc)
    try:
        t.Start()
        # turn off TemporaryViewPropertiesMode & reveal hidden elements
        doc.ActiveView.TemporaryViewModes.DeactivateAllModes()

        settings = DB.OverrideGraphicSettings().Dispose()

        settings = DB.OverrideGraphicSettings()

        for room in rooms:
            doc.ActiveView.SetElementOverrides(room.Id, settings)

        t.Commit()
    except Exception as e:
        logger.error(e)
1 Like

with thanks for this @Jean-Marc

1 Like