Nodes/Comfyui_PDuse/PD文本列表解包
ComfyUI Node

PD文本列表解包

PD文本列表解包 pulls one caption out of a batch by index — the loop's best friend

By 7BEII·Created 2 years ago·Updated 15 days ago· 53
PD文本列表解包
    • text_content
    • filename
    • total_count
    text_list
    filename_text
    index0

    The inverse of the pack node, and the key to text loops

    PD_TextListUnpack ("PD文本列表解包") does the boring but crucial job of pulling a single item out of a text batch: you give it a text_list, its matching filename_text, and an index, and it returns that one caption, that one filename, and the total count. It's the mirror image of PD_TextListPack, and together they bookend the pack's batch text pipeline.

    Why does a "get item at index" node deserve its own page? Because most ComfyUI text consumers only accept a single string, and ComfyUI's loop nodes hand you an index as you iterate. This node is the bridge: wire the batch into it, drive index from a counter or loop, and each iteration feeds one caption to the downstream node. It's the same "many wires, one list, pluck what you need" philosophy the KB lays out in comfyui-node-plumbing.md - the plumbing layer that makes a graph act like a program.

    How it works

    The mechanism is deliberately forgiving. It checks the list isn't empty, parses filename_text into lines, and pulls text_list[index]. The noteworthy bit is bounds handling: if index is out of range (negative, or beyond the last item), it doesn't error - it clamps to the nearest valid index (first or last) and logs a warning. If there's no filename at that index, it fabricates a file_N.txt default. So it can't crash your workflow, but it also can't tell you "that index doesn't exist" - which is either friendly or dangerous depending on your workflow.

    Inputs and outputs

    • text_list - the batch to pull from (list input).
    • filename_text - newline-joined filenames, parallel to the list.
    • index - zero-based position, 0 is the first item. Default 0.
    • Outputs: text_content (the caption at that index), filename, total_count (how many items are in the batch).

    Installing it

    Part of Comfyui_PDuse:

    cd ComfyUI/custom_nodes
    git clone https://github.com/7BEII/Comfyui_PDuse.git
    cd Comfyui_PDuse
    pip install -r requirements.txt
    

    Or search "Comfyui_PDuse" in ComfyUI Manager and restart.

    The one thing to remember

    The silent clamping is the feature and the trap. In a loop you control, it's great - out-of-range just repeats the last item. In a workflow where you're manually setting index and expecting an error when you go past the end, you'll get the final caption instead and might not notice. Also note it doesn't validate that text_list and filename_text line up: if they're different lengths, the filename at that index may belong to a different item or be a fabricated default. Keep the pairing intact upstream (the pack's sort node is built exactly for that) and this is the cleanest way to iterate a text batch one item at a time.

    CategoryPDuse/Text

    Inputs (3)

    NameTypeDefaultDescription
    text_listSTRING
    filename_textSTRING
    indexINT00–9999

    Outputs (3)

    NameTypeDescription
    text_contentSTRING
    filenameSTRING
    total_countINT