Nodes/Comfyui-xbhh-main/xbhh 动态文本 ⚡
ComfyUI Node

xbhh 动态文本 ⚡

Prompts and filenames that fill in the date, a counter, or a random number themselves

By xbhh123456·Created 8 months ago·Updated 18 days ago· 11
xbhh 动态文本 ⚡
    • text
    text文件_%date%_%counter:3%
    seed0
    reset_counterfalse

    The XBHH dynamic text node is a small text transformer that lives for one trick: you write %date% or %counter:3% inside a string, and it replaces those tokens with real values when the graph runs. It's the kind of node that's boring to describe and quietly saves you every single time you batch-generate or save files. One output, one text widget, done.

    You'd reach for it in two situations. First, filenames: the xbhh save node and plenty of others accept a prefix, but this node lets you build the whole string with a timestamp, a zero-padded counter, or a UUID before it hits the encoder. Second, prompts: %random:1-100% or %choice:A|B|C% inside your positive prompt gives you cheap, scripted variation per run - the poor man's dynamic prompt batching.

    The variable set

    The text field accepts any of these, all wrapped in %...%:

    • Dates and time - %date% (YYYY-MM-DD), %time%, %datetime%, and custom formats like %date:MM-dd%. Format tokens use YYYY/MM/dd/HH/mm/ss style, which it translates to Python's strftime internally.
    • Randomness - %random:1-100% for a random integer in a range, %choice:red|blue|green% to pick one item at random, %uuid% for a unique ID (you can ask for a shorter one with %uuid:8%).
    • A counter - %counter% increments each run; %counter:3% pads it to three digits, so you get 001, 002, 003. This is the one that makes batch filenames not collide.
    • Pieces of the calendar - %year%, %month%, %day%, %weekday% (with :en or :short variants if you want English).
    • Environment - %env:VARIABLE% reads an OS environment variable, which is a niche flex but handy for machine-specific paths.

    Unknown tokens are left untouched rather than erroring, so a stray %foo% just stays in your string.

    The inputs that matter

    • text - the template. Multiline. The default 文件_%date%_%counter:3% shows the intended use.
    • seed (optional) - seeds the random bits. 0 means "random every time," which is the default. Set a fixed seed and your random/choice picks become reproducible run to run.
    • reset_counter (optional) - a boolean that zeroes the per-node counter back to 0. Flip it to true once (or wire a switch) when you start a new batch and want numbering to restart.

    The single output is text (STRING). The counter is tracked per node by its internal unique ID, so two of these nodes in one workflow don't share a counter.

    Installing it

    It's part of the XBHH kit - install the pack, get this node:

    cd ComfyUI/custom_nodes
    git clone https://github.com/xbhh123456/Comfyui-xbhh-main.git
    cd Comfyui-xbhh-main
    pip install -r requirements.txt
    

    Or via ComfyUI Manager, searching xbhh-lora. Then restart. No models, no keys, nothing heavy - the whole kit's only real dependency is openpyxl for its Excel viewer.

    Gotchas worth knowing

    The counter resets when ComfyUI restarts - it's in-memory, not persisted, which is actually the behavior you want for a session-scoped batch. And if you pipe this into a text encoder, remember ComfyUI's own dynamicPrompts feature may also be fighting over the same string; this node runs its substitution at execution time, so tokens that remain (like {red|blue} wildcards meant for the dynamic-prompts system) are left alone for that system to handle. When things don't render the way you expected, check the node's own output first - a plain text display node will show you exactly what it produced.

    CategoryXBHH

    Inputs (3)

    NameTypeDefaultDescription
    textSTRING文件_%date%_%counter:3%
    seedoptINT00–18446744073709550000随机种子,0表示每次随机
    reset_counteroptBOOLEANfalse重置计数器

    Outputs (1)

    NameTypeDescription
    textSTRING