Cycle Theme
Description
Cycles Revit through four theme presets: matched Light/Dark UI and canvas combos, plus mixed pairs
Code
pyRevit# -*- coding: utf-8 -*-
# V1.0.1 26-08-10
__title__ = 'Cycle\nTheme'
__author__ = 'bimgineer'
__min_revit_ver__ = 2024
__doc__ = 'Cycle Revit UI theme and canvas color scheme through preset combinations.'
from pyrevit import EXEC_PARAMS
from Autodesk.Revit.UI import UIThemeManager, UITheme
PAIRS = [
(UITheme.Light, UITheme.Light),
(UITheme.Dark, UITheme.Dark),
(UITheme.Dark, UITheme.Light),
(UITheme.Light, UITheme.Dark),
]
def cycle_theme():
"""Advance the UI/canvas theme pair by one step."""
# 'Follow system colour theme' silently reverts anything we set.
UIThemeManager.FollowSystemColorTheme = False
current = (UIThemeManager.CurrentTheme, UIThemeManager.CurrentCanvasTheme)
index = PAIRS.index(current) + 1 if current in PAIRS else 0
UIThemeManager.CurrentTheme, UIThemeManager.CurrentCanvasTheme = \
PAIRS[index % len(PAIRS)]
# Only ever run on a real button click. pyRevit evaluates extension python at
# session load; without this guard the theme flips on every Reload.
if EXEC_PARAMS.executed_from_ui:
cycle_theme()
# THIS SCRIPT IS DEPRECATED
# I'm leaving it here for archive purposes & so people can learn.
# -*- coding: utf-8 -*-
# V1.0.0
__title__ = 'Cycle\nTheme'
__author__ = 'bimgineer'
__min_revit_ver__ = 2024
__doc__ = 'Cycle Revit UI theme and canvas color scheme through preset combinations.'
from Autodesk.Revit.UI import UIThemeManager, UITheme
pairs = [
(UITheme.Light, UITheme.Light),
(UITheme.Dark, UITheme.Dark),
(UITheme.Dark, UITheme.Light),
(UITheme.Light, UITheme.Dark),
]
current = (UIThemeManager.CurrentTheme, UIThemeManager.CurrentCanvasTheme)
next_pair = pairs[(pairs.index(current) + 1) % 4] if current in pairs else pairs[0]
UIThemeManager.CurrentTheme, UIThemeManager.CurrentCanvasTheme = next_pair