Nodes/Sage Utils/Text Select Line
ComfyUI Node

Text Select Line

Pick a line by number, and let it be clamped for you

By arcum42·Created 2 years ago·Updated 28 days ago· 33
Text Select Line
    • selected_line
    text
    line_number0

    The deterministic sibling of the pack's Text Random Line: instead of picking a random line from your list, this one returns the line at an index you specify. Feed it a list of prompts and a number, and it hands back exactly that line - the index, not the luck. It's the node you use when the choice shouldn't be random, like driving a workflow from a batch counter.

    How it works

    Two inputs: text (multiline, one candidate per line) and line_number (an int, default 0). The node splits the text into non-empty, whitespace-stripped lines and returns the one at the given index. Two details make it friendlier than writing this yourself:

    • It's 0-based. Line 0 is the first line. Anyone coming from a 1-based mental model will trip on this exactly once, so just know it going in.
    • It clamps. Ask for line 99 when there are three lines and you get the third line, not an error. The node pins the index to the valid range rather than blowing up mid-batch.

    The output is the selected line as a string (selected_line). Blank lines are skipped, same as the random-line node, so your list can have gaps.

    When you'd use it

    The classic pattern is driving variations from a counter or a batch loop: line 0 on run one, line 1 on run two, and so on. Wire line_number from a batch index or a widget and you get a reproducible sequence of prompts with zero manual editing. It's also handy for choosing from a small config list - pick a style from a list by its position, select a named preset. And because it clamps, you can let the batch index run past the list length without the workflow dying; you'll just repeat the last line.

    Installing it

    Part of the Sage Utils pack - ComfyUI Manager (search Sage Utils) or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/arcum42/ComfyUI_SageUtils
    cd ComfyUI_SageUtils
    pip install -r requirements.txt
    

    Restart ComfyUI. Only pip dependency is dynamicprompts; no model downloads.

    The trap

    The 0-based indexing is the whole gotcha - there's no setting to flip it to 1-based. If your list has five lines and you're expecting the fifth one to be line 5, it's line 4. Double-check the index you're feeding it, and if you're coming from a node that was 1-based, subtract one. Also remember it operates on non-empty lines: if your text has blank lines, the numbering skips them, which can shift every index below where you think it is.

    CategorySage Utils/text/line

    Inputs (2)

    NameTypeDefaultDescription
    textSTRINGText to select a specific line from.
    line_numberINT0Line number to return (0-based index).

    Outputs (1)

    NameTypeDescription
    selected_lineSTRINGOutput value for selected_line.