Skip to content

tabs

Document colorizer python API.

Attributes

Functions

hex_to_brush(color_hex)

Convert hex color to WPF brush.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def hex_to_brush(color_hex):
    """Convert hex color to WPF brush."""
    return Media.SolidColorBrush(
        Media.ColorConverter.ConvertFromString(color_hex)
    )

hex_from_brush(solid_brush)

Convert WPF brush to hex color.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def hex_from_brush(solid_brush):
    """Convert WPF brush to hex color."""
    color = solid_brush.Color
    color_hex = ''.join(
        '{:02X}'.format(int(x)) for x in
        [color.A, color.R, color.G, color.B]
        )
    return '#' + color_hex

get_tabcoloring_theme(usercfg)

Get tab coloring theme from settings.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def get_tabcoloring_theme(usercfg):
    """Get tab coloring theme from settings."""
    tabcfgs = _get_tabcoloring_cfgs(usercfg)

    theme = types.TabColoringTheme()
    theme.SortDocTabs = _get_sort_colorize_docs(tabcfgs)
    theme.TabStyle = _get_tabstyle(tabcfgs)
    theme.FamilyTabStyle = _get_family_tabstyle(tabcfgs)

    theme.TabOrderRules = _get_tab_orderrules(tabcfgs)
    theme.TabFilterRules = _get_tab_filterrules(tabcfgs)

    return theme

reset_tab_ordercolors(usercfg, theme)

Reset tab order colors to internal default.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def reset_tab_ordercolors(usercfg, theme):
    """Reset tab order colors to internal default."""
    tabcfgs = _get_tabcoloring_cfgs(usercfg)
    theme.TabOrderRules = _get_tab_orderrules(tabcfgs, default=True)

set_tabcoloring_theme(usercfg, theme)

Set tab coloring theme in settings.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def set_tabcoloring_theme(usercfg, theme):
    """Set tab coloring theme in settings."""
    tabcfgs = _get_tabcoloring_cfgs(usercfg)

    _set_sort_colorize_docs(tabcfgs, theme)
    _set_tabstyle(tabcfgs, theme)
    _set_family_tabstyle(tabcfgs, theme)

    _set_tab_ordercolors(tabcfgs, theme)
    _set_tab_filtercolors(tabcfgs, theme)

get_tab_orderrule(theme, index)

Get coloring rule from active theme, at index.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def get_tab_orderrule(theme, index):
    """Get coloring rule from active theme, at index."""
    return hex_from_brush(theme.TabOrderRules[index].Brush)

add_tab_orderrule(theme, color)

Add coloring rule to active theme.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def add_tab_orderrule(theme, color):
    """Add coloring rule to active theme."""
    theme.TabOrderRules.Add(
        types.TabColoringRule(hex_to_brush(color))
        )

remove_tab_orderrule(theme, index)

Remove coloring rule at index, from active theme.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def remove_tab_orderrule(theme, index):
    """Remove coloring rule at index, from active theme."""
    theme.TabOrderRules.RemoveAt(index)

update_tab_orderrule(theme, index, color)

Update coloring rule at index, on active theme.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def update_tab_orderrule(theme, index, color):
    """Update coloring rule at index, on active theme."""
    tor = theme.TabOrderRules[index]
    tor.Brush = hex_to_brush(color)

get_tab_filterrule(theme, index)

Get coloring filter rule from active theme, at index.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def get_tab_filterrule(theme, index):
    """Get coloring filter rule from active theme, at index."""
    tfr = theme.TabFilterRules[index]
    color = tfr.Brush.Color
    color_hex = ''.join(
        '{:02X}'.format(int(x)) for x in
        [color.A, color.R, color.G, color.B]
        )
    return '#' + color_hex, str(tfr.TitleFilter)

add_tab_filterrule(theme, color, title_filter)

Add coloring filter rule to active theme.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def add_tab_filterrule(theme, color, title_filter):
    """Add coloring filter rule to active theme."""
    fc = types.TabColoringRule(hex_to_brush(color), title_filter)
    theme.TabFilterRules.Add(fc)

remove_tab_filterrule(theme, index)

Remove coloring filter rule at index, from active theme.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def remove_tab_filterrule(theme, index):
    """Remove coloring filter rule at index, from active theme."""
    theme.TabFilterRules.RemoveAt(index)

update_tab_filterrule(theme, index, color=None, title_filter=None)

Update coloring filter rule at index, on active theme.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def update_tab_filterrule(theme, index, color=None, title_filter=None):
    """Update coloring filter rule at index, on active theme."""
    tfr = theme.TabFilterRules[index]
    if color:
        tfr.Brush = hex_to_brush(color)
    if title_filter:
        tfr.TitleFilter = Regex(title_filter)

update_tabstyle(theme, tab_style)

Update current tab style.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def update_tabstyle(theme, tab_style):
    """Update current tab style."""
    for ts in types.TabColoringTheme.AvailableStyles:
        if ts.Name == tab_style.Name:
            theme.TabStyle = ts

update_family_tabstyle(theme, tab_style)

Update current family tab style.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def update_family_tabstyle(theme, tab_style):
    """Update current family tab style."""
    for ts in types.TabColoringTheme.AvailableStyles:
        if ts.Name == tab_style.Name:
            theme.FamilyTabStyle = ts

get_doc_colorizer_state()

Get state of document colorizer.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def get_doc_colorizer_state():
    """Get state of document colorizer."""
    return types.DocumentTabEventUtils.IsUpdatingDocumentTabs

get_styled_slots()

Get list of current styling slots.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def get_styled_slots():
    """Get list of current styling slots."""
    active_theme = types.DocumentTabEventUtils.TabColoringTheme
    if active_theme:
        return list(active_theme.StyledDocuments)

toggle_doc_colorizer()

Toggle state of document colorizer.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def toggle_doc_colorizer():
    """Toggle state of document colorizer."""
    if types.DocumentTabEventUtils.IsUpdatingDocumentTabs:
        types.DocumentTabEventUtils.StopGroupingDocumentTabs()
    else:
        types.DocumentTabEventUtils.StartGroupingDocumentTabs(HOST_APP.uiapp)
    return types.DocumentTabEventUtils.IsUpdatingDocumentTabs

reset_doc_colorizer()

Reset document colorizer.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def reset_doc_colorizer():
    """Reset document colorizer."""
    types.DocumentTabEventUtils.ResetGroupingDocumentTabs()

init_doc_colorizer(usercfg)

Initialize document colorizer from settings.

Source code in pyrevitlib/pyrevit/revit/tabs.py
def init_doc_colorizer(usercfg):
    """Initialize document colorizer from settings."""
    uiapp = HOST_APP.uiapp
    if HOST_APP.is_newer_than(2018):
        current_tabcolorizer = \
            envvars.get_pyrevit_env_var(envvars.TABCOLORIZER_ENVVAR)

        new_theme = get_tabcoloring_theme(usercfg)

        # cancel out the colorizer from previous runtime version
        if current_tabcolorizer:
            # TODO: adopt the previous slots state
            # prev_theme = current_tabcolorizer.TabColoringTheme
            # if prev_theme:
            #     new_theme.InitSlots(prev_theme)
            current_tabcolorizer.StopGroupingDocumentTabs()

        # start or stop the document colorizer
        types.DocumentTabEventUtils.TabColoringTheme = new_theme
        if usercfg.colorize_docs:
            types.DocumentTabEventUtils.StartGroupingDocumentTabs(uiapp)
        else:
            types.DocumentTabEventUtils.StopGroupingDocumentTabs()

        # set the new colorizer
        envvars.set_pyrevit_env_var(
            envvars.TABCOLORIZER_ENVVAR,
            types.DocumentTabEventUtils
            )