<Code Lib>
👍 1 👁 181

Cycle Theme

by @bimgineer · Jul 10, 2026
Tags

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()
guest@rvtdocs: ~/discuss

Want to join the conversation?

rvtdocs auth

Share & save code Comment on pages Save bookmarks Upvote snippets Gamification

Loading…