BK Color Selector
Pick one color out of a palette string, by index
- STRING
This is the smallest node in the ComfyUI_BaiKong_Node pack, and it does exactly one thing: you paste in a comma-separated list of hex colors, give it an index, and it hands back the color at that position. That's it. No ML, no math, no models.
So why would you want it? Because it turns a palette string into a selectable value inside your graph. The pack's other color nodes (like BK Img To Color) spit out comma-separated color strings as one opaque blob. BK Color Selector is the tool that unpacks one of those blobs so a single color can drive a text overlay, feed a gradient, or get pushed through BK Color Limit / BK Color Contrast. It's the plumbing between "here's a palette" and "use this one."
How it works
The mechanism is deliberately trivial: split the input string on your chosen symbol (default ,), strip whitespace around each entry, clamp split_count into the bounds of the list, and return the color at that position. split_count is 1-based - so 1 grabs the first color. There's a console log line telling you how many colors it parsed and which one it selected, which saves debugging a malformed palette.
The one place it's not forgiving: it validates the selected color against ^#(?:[0-9a-fA-F]{3}){1,2}$ and raises a ValueError if it's not a valid hex. Most nodes in this pack quietly fall back to a default on bad input; this one hard-errors. So if your workflow suddenly throws, check you didn't put a space-separated list in there (it only splits on your symbol), or a color with a typo.
Inputs and outputs
- hex_colors - the multiline string field, e.g.
#FF0036, #FF5000, #0065ff, #3D7FFF. - symbol - the delimiter (default
,). Useful if your palette is separated by semicolons or newlines instead. - split_count - which color to grab, 1-based, clamped to the list length (max 4096).
Output is a single STRING - the chosen hex. After a run the node paints the selected color as an inline swatch, same as the other color nodes in the pack, so you get a quick visual confirmation that index 3 was the blue you meant.
Install
It ships with the whole pack:
cd ComfyUI/custom_nodes
git clone https://github.com/JayLyu/ComfyUI_BaiKong_Node
cd ComfyUI_BaiKong_Node
pip install -r requirements.txt
Restart ComfyUI, or install "ComfyUI_BaiKong_Node" via ComfyUI Manager. Dependencies (scikit-learn, scipy, opencv-python, scikit-image, matplotlib) are shared across the pack - all CPU-side, zero model downloads.
Gotchas
Beyond the strict hex validation, the only real gotcha is that split_count reads as a 1-based index while the internal list is 0-based - so a value of 1 returns the first color, and you can't select index 0. If you're chaining a split_count straight out of a math node that thinks in 0-based indices, add one first. For just testing palettes, it's the sort of node you drag in, click, and forget - which is honestly a compliment.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| hex_colors | STRING | #FF0036, #FF5000, #0065ff, #3D7FFF | — |
| symbolopt | STRING | , | — |
| split_countopt | INT | 11–4096 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |