Count Text Lines
Turn a block of text's line count into a usable INT
- INT
Exactly what it sounds like: feed it a block of text, get back how many lines are in it, as an actual INT you can wire into other nodes rather than eyeballing it yourself.
How it works
It splits the input text on line breaks and returns the length of that list. An empty string returns 0 outright rather than 1, which is the behavior you'd actually want here even though a naive line-count could argue either way.
The inputs and outputs that matter
text- the multiline string to count. That's the entire input.
Output: a single INT, the number of lines found. That's genuinely the whole node - one input, one output, no widgets to tune. The value isn't in the logic, which you could write yourself in one line of Python; it's in having a ready-made node so you don't have to drop into a custom-script node just to count lines every time you need the number in your graph.
What it's actually for
This pairs naturally with the other two text nodes in the pack. Run RemoveBlankLines first if you want a count that reflects real content rather than counting stray empty lines too - CountTextLines doesn't filter anything itself, it counts exactly what splitlines() sees, blanks included. Once you've got a clean count, it's the "how many things am I actually iterating over" building block for a text-driven batch pipeline: wire it into a loop-limit check, or use it alongside something like IncrementEveryN (same pack) to know how many steps a full pass through your prompt list actually needs, without hardcoding the number and having it silently go stale the next time you edit the list.
Installing it
Search cspnodes in ComfyUI Manager, or clone it directly:
cd ComfyUI/custom_nodes
git clone https://github.com/cerspense/ComfyUI_cspnodes
Restart after. The pack's single Python file imports diffusers and pymediainfo unconditionally at the top, for other nodes in the pack that actually need them. This node touches neither - but if either import fails on your system, the entire cspnodes category vanishes from your node list, this one included, so check your startup log for an import error before assuming anything's specifically broken here.
Where people get tripped up
There's not much surface area for problems with a node this small, but the one thing worth remembering: it counts blank lines too, since it does no filtering of its own. If a count looks higher than you expected, it's probably picking up empty lines you didn't notice were there - run the text through RemoveBlankLines first if that matters for what you're building.
The other thing to keep in mind is that this counts lines, not sentences or entries - if your text list wraps long entries across multiple visual lines (say, a prompt that got soft-wrapped by whatever editor you pasted it from), each wrapped segment counts separately even though it's conceptually one item. Keep one entry per line if you're relying on this count to line up with something like a line-indexed iterator downstream.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |