Nodes/Nukun_ComfyUI_Nodes/Incrementing Int to String (Nukun)
ComfyUI Node

Incrementing Int to String (Nukun)

A counter that writes the number into your filenames, minus the two-node rigmarole

By OnekoSL·Created 3 months ago·Updated 11 days ago· 1
Incrementing Int to String (Nukun)
    • STRING
    • INT
    • raw_value
    value0
    min_value0
    max_value9999

    Every batch workflow eventually needs a number that ticks up each run - a run counter in the filename, an index that feeds a folder cycler, a label that distinguishes frame 1 from frame 100. The classic ComfyUI way is two nodes: an Int primitive and an "Int to String" converter, wired together and converted to inputs so the value can flow as text. It works. It's also a small pile of graph spaghetti for something that should be one widget.

    NukunIncrementingIntString collapses that into a single node from the Nukun pack. It takes one integer, wraps it inside a min/max range, and hands you the result as a plain string, ready for a filename builder or a text concat.

    How it works

    You get three integer widgets. value is the counter - and here's the useful part - it has ComfyUI's control_after_generate support built in, so right-click it and set increment, and the number advances by one after every generation. min_value and max_value define the cycle: when the value walks past max_value, it wraps back around to min_value. If you accidentally set max below min, the node just swaps them rather than erroring out - a small touch, but a friendly one.

    It's a pure function under the hood: low + ((value - low) % cycle_size). No state, no hidden math, deterministic every time.

    The outputs

    Three, so you can use it in whatever form fits:

    • STRING - the wrapped value as a plain string. No thousands-separator commas, which is the usual gotcha with stock converters when your count crosses 999 and suddenly filenames read "1,000".
    • INT - the same wrapped number as an integer, for anything that wants the math type.
    • raw_value - the unwrapped input, so you can see the "real" counter before cycling if you ever need to know how many total runs happened.

    The typical wiring: STRING into a Save Image filename template or an Anywhere/reroute that feeds text nodes, control_after_generate = increment on the value widget, and you have per-run numbering with zero extra nodes.

    Installing it

    Part of the Nukun pack, so install once and you get all its nodes:

    cd ComfyUI/custom_nodes
    git clone https://github.com/OnekoSL/Nukun_ComfyUI_Nodes.git
    

    Restart ComfyUI (or search "Nukun" in ComfyUI Manager). No model downloads, no heavy deps - numpy, Pillow, scipy, PyWavelets at most.

    The one trap: "after generate" semantics

    This is the same gotcha that bites everyone with seed nodes, worth repeating here: control_after_generate fires after the run, so the number shown in the widget is the one that will be used next, not the one that just produced the image you're looking at. If you want the printed filename to match the run that made it, flip ComfyUI's global "widget control mode" to Before in settings, once. Do that and this node becomes the quiet, dependable counter you forgot was even there.

    CategoryNukun/Text

    Inputs (3)

    NameTypeDefaultDescription
    valueINT00–18446744073709550000Integer value to output as a plain string. The frontend can increment it after queueing.
    min_valueINT00–18446744073709550000Lowest value in the output cycle.
    max_valueINT99990–18446744073709550000Highest value in the output cycle. If it is lower than min_value, the node swaps both values.

    Outputs (3)

    NameTypeDescription
    STRINGSTRING
    INTINT
    raw_valueINT