I would like to experiment with additional ways of colourizing the open tabs – perhaps something where I could force a particular tab to have a red border so I can quickly see which one to return to after looking at a different view. Since it’s not a PyRevit button, I can’t alt-click to investigate or edit the script.
Is there an editable python script somewhere in the folder structure, and if so where?
Alternatively, as long as tab colouring is addressable with the Revit API, perhaps I can make my own script to do this. However, I searched the API for ‘tab’ and none of the options appeared to be referring to the kind of tabs I’m talking about. Any suggestions would be most welcome.
its better to expose the code here, to get audience
bundle
title:
ru: Окрасить вкладки
fr_fr: Colorer les onglets
en_us: Tab Coloring
tooltip:
ru: Делает все возможное для визуального разделения открытых документов.
fr_fr: Améliore la distinction entre les documents ouverts
en_us: Does its best at visually separating open documents
min_revit_version: 2019
context: zero-doc
python
"""Does its best at visually separating open documents."""
#pylint: disable=import-error,invalid-name,broad-except,superfluous-parens
import re
from pyrevit import HOST_APP
from pyrevit.runtime.types import DocumentTabEventUtils
from pyrevit.coreutils.ribbon import ICON_MEDIUM
from pyrevit import script
from pyrevit.userconfig import user_config
from pyrevit.revit import tabs
from pyrevit import forms
from pyrevit.revit import ui
import pyrevit.extensions as exts
output = script.get_output()
COLOR_TAG_STYLE_TEMPLATE = \
'.doc-color-tag{0} {{ '\
'background-color: #{1}; '\
'color: white; '\
'padding: 1px 5px 1px 5px;'\
' }}'
COLOR_TAG_HTML_TEMPLATE = '<a title="{0}" class="doc-color-tag{1}">{0}</a>'
def __selfinit__(script_cmp, ui_button_cmp, __rvt__):
on_icon = ui.resolve_icon_file(script_cmp.directory, exts.DEFAULT_ON_ICON_FILE)
off_icon = ui.resolve_icon_file(script_cmp.directory, exts.DEFAULT_OFF_ICON_FILE)
button_icon = script_cmp.get_bundle_file(
on_icon if user_config.colorize_docs else off_icon
)
ui_button_cmp.set_icon(button_icon, icon_size=ICON_MEDIUM)
def print_slots():
"""Print currently used colors on doc colorizer"""
print("Active: %s" % tabs.get_doc_colorizer_state())
style_slots = tabs.get_styled_slots()
if style_slots:
index = 0
print("Count: %s" % len(style_slots))
for slot in style_slots:
color = tabs.hex_from_brush(slot.Rule.Brush)[-6:]
output.add_style(
COLOR_TAG_STYLE_TEMPLATE.format(index, color)
)
color_tag = COLOR_TAG_HTML_TEMPLATE.format(color, index)
output.print_html(
'Slot: {} Id: {} with {}{}'.format(
index,
slot.Id,
color_tag,
' (Family)' if slot.IsFamily else ''
)
)
index += 1
def reset_slots():
"""Reset doc colorizer"""
tabs.reset_doc_colorizer()
if __name__ == '__main__':
if __shiftclick__: #pylint: disable=undefined-variable
selected_option = forms.CommandSwitchWindow.show(
["List Document Colors", "Reset Theme"],
message="Select option:"
)
if selected_option == "List Document Colors":
print_slots()
elif selected_option == "Reset Theme":
reset_slots()
else:
is_active = tabs.toggle_doc_colorizer()
script.toggle_icon(is_active)
you can it in your own button, i migrated a lot of buttons…