ZML_文本计数
A persistent counter that survives restarts, backed by a txt file
- 当前计数
- 状态信息
Most counters in ComfyUI live in memory and die with the process. ZML_TextCounter is different: it keeps its number in a txt file on disk, reads it, adds or subtracts one (or zeroes it), and writes it back. Because the state lives in a file rather than in the node, it survives restarts, it's shared between every instance of the node that points at the same file, and another script can read or modify it outside ComfyUI entirely.
The default file lives inside the pack's directory as 计数器.txt; if you set the txt路径 input, it uses your file instead. That's the useful trick - point two copies of the node at the same path and they act as one counter, or point it at a file your shell scripts also touch.
The inputs that matter
- txt路径 - the file path. Leave it empty to use the pack's default counter file.
- 增加 -
True= +1,False= −1. The tooltip says it plainly. - 执行操作 -
Trueperforms the add/subtract;Falsejust reads the current value and returns it untouched. Handy when you want to check a counter without changing it, or when you want to gate the increment from upstream logic. - 清零 -
Trueresets the count to zero, and per the tooltip it takes priority over the increment/decrement operation.
Outputs are 当前计数 (INT) and 状态信息 (STRING), the latter being a human-readable note about what happened. It's marked as an output node, so it always runs and is a valid terminal for a workflow.
How to actually use it
The clean use case is numbering: a batch counter for filenames that has to keep counting across a ComfyUI restart, or a shared "run number" that a save node, a caption, and a log all draw from. Because it reads and writes a real file, you can also wire it as the loop counter for a workflow that iterates and needs to remember where it stopped.
Worth knowing before you rely on it: writing a file every run is fine for single-step use, but if you wire this into a long batch, every image means one file write and one read - trivial overhead, but it means the counter advances once per execution, not once per batch frame. And since the state is just a text file, two ComfyUI instances writing the same path will step on each other - keep one writer per file. It's a genuinely simple node (a few lines of file I/O), so there's not much to break; the failure mode is picking a path you can't write to, in which case it falls back to 0.
Install
Part of ComfyUI-ZML-Image: ComfyUI Manager → search "ComfyUI-ZML-Image", or cd ComfyUI/custom_nodes && git clone https://github.com/zml-w/ComfyUI-ZML-Image, restart. Displayed as ZML_文本计数 in the Chinese-default UI - the English patch translates it. No models or extra dependencies.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| txt路径 | STRING | — | |
| 增加 | BOOLEAN | true | True=增加,False=减少 |
| 执行操作 | BOOLEAN | true | True=执行加减操作,False=不执行 |
| 清零 | BOOLEAN | false | True=直接清零计数,优先级高于增减操作 |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| 当前计数 | INT | — |
| 状态信息 | STRING | — |