xbhh txt选择器
A dropdown that spits out a random line from a text file — your wildcard without the plugin
- STRING
Every once in a while you want a prompt element chosen at random - a random character, a random style, a random location - without committing to a full dynamic-prompt system. XBHHTxtSelector is the minimal version of that: pick a .txt file from a dropdown, and each run it returns one random non-empty line as a string. That's it. One output, one seed, done.
It's the file-based cousin of the kit's dynamic text node. Where %choice:A|B|C% inline is good for a handful of options, this node shines when your option list lives in a file - because you can edit the file without touching the workflow, and because a file can hold hundreds of lines without clogging your node widgets.
How it works
The dropdown (txt_file) is populated at node load from two locations, in this order:
- The pack's own
xbhh/folder - it ships with a sample随机碧蓝航线角色.txt(random Azur Lane characters), which is why you'll see a Chinese filename as the default choice. ComfyUI/user/xbhh/txt/- a directory the node creates for you on first use. Anything you drop in there (UTF-8, one option per line) shows up in the dropdown automatically.
At execution it reads the file fresh, strips blank lines, and picks one at random. The IS_CHANGED method returns the seed, which tells ComfyUI to re-run the node whenever the seed changes - so bumping the seed widget rerolls the pick without rerunning the whole graph if you have execution caching in play.
The inputs
- txt_file - the dropdown of available
.txtfiles. - seed - an integer, default 0. Change it to reroll.
The single output is a STRING - wire it into a CLIP Text Encode, a prompt concat node, or your filename builder. It pairs naturally with the kit's Prompt Formatter: random raw tag out of the selector, cleaned up by the formatter, then encoded.
Installing it
It's part of the XBHH pack:
cd ComfyUI/custom_nodes
git clone https://github.com/xbhh123456/Comfyui-xbhh-main.git
cd Comfyui-xbhh-main
pip install -r requirements.txt
Or ComfyUI Manager → search xbhh-lora → restart.
Gotchas
- New files need a refresh. The dropdown is scanned at node load, so a
.txtyou drop intouser/xbhh/txt/mid-session won't appear until you reload the workflow (or restart the frontend). That's the same "built at load time" behavior as the pack's JSON preset selector. - Empty file or missing file → returns an empty string, which encodes as an empty prompt block. Not a crash, but confusing if you forget where the file lives.
- Encoding matters. It reads UTF-8; if your text file is Windows-1252 or has a stray BOM, you'll get mojibake or the line may not match. Save your option files as UTF-8.
- The pack also ships a sibling
PromptRandomizer("xbhh txt随机抽取") that takes a full file path instead of a dropdown - use that one if you want to point at a file anywhere on disk rather than managing theuser/xbhh/txt/folder.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| txt_file | COMBO | 随机碧蓝航线角色.txt | 1 options: 随机碧蓝航线角色.txt |
| seed | INT | 00–18446744073709550000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |