Hello,
Is it possible to define the colors showing in the pyrevit.forms.
select_swatch
window ?
1 Like
Hi @danselkaz ,
unfortunately there’s no easy way to define those colors.
You can create your own select_swatch function by copy these lines of code and replacing the colors.COLORS.values()
line with your list of colors.
The current colors are defined in the pyrevit.coreutils.colors
module, but you can create your own colors using the pyrevit.coreutils.colors.RGB
class.
1 Like
Thank you ! I will try this
Ok it seems to work like this :
import os
import os.path as op
from pyrevit import forms
from pyrevit.forms import utils, __init__
from pyrevit import coreutils
from pyrevit.coreutils import colors
import mycolors
XAML_FILES_DIR = op.dirname(__file__)
def select_swatch_mycolors(title='Select Color Swatch', button_name='Select'):
"""Standard form for selecting a color swatch.
Args:
title (str, optional): swatch list window title
button_name (str, optional): swatch list window button caption
Returns:
pyrevit.coreutils.colors.RGB: rgb color
Example:
>>> from pyrevit import forms
>>> forms.select_swatch(title="Select Text Color")
... <RGB #CD8800>
"""
itemplate = utils.load_ctrl_template(
os.path.join(XAML_FILES_DIR, "SwatchContainerStyle.xaml")
)
swatch = forms.SelectFromList.show(
mycolors.COLORS.values(),
title=title,
button_name=button_name,
width=400,
multiselect=False,
item_template=itemplate
)
return swatch
selected_color = select_swatch_mycolors(
title='Selectionner une couleur',
button_name='Test button name'
)
print selected_color
I just had to duplicate SwatchContainerStyle.xaml in my extension library and create my own library of colors named mycolors.py in the library also
2 Likes