Nodes/honda-nodes/πŸ“‹ Array Slice
ComfyUI Node

πŸ“‹ Array Slice

Chop a long list into batches without deleting anything

By AvarayΒ·Created 14 days agoΒ·Updated 12 days agoΒ· 0
πŸ“‹ Array Slice
    • Array
    • Count
    β—„arrayβ€”β–Ί
    β—„start0β–Ί
    β—„end-1β–Ί
    β—„step1β–Ί
    β—„trim_itemstrueβ–Ί

    The "do this 200 times, a batch at a time" node

    You have 200 prompts, or 200 filenames from πŸ“‚ List Files, and you want to work through them in chunks of 20 rather than one monstrous run. Array Slice is how you take chunk three without touching the original list: give it a start, an end, and a step, and it hands back the sub-list.

    It's the least glamorous node in the πŸ“‹ Array group and the one that makes long-running pipeline work possible. Editing a 200-line text block and hoping you didn't break anything is not a workflow; slicing it by index is.

    How it works

    Python slicing, wrapped in a node. That's the honest description, and it's good news - if you know what items[20:40] does, you already know this node. Items are split on newlines, trimmed if asked, then [start:end:step] is applied and the survivors are re-joined with newlines.

    The one deviation worth memorising: end = -1 is special-cased to mean "to the end of the array", not "everything except the last item". The author's tooltip says as much, and the source treats -1 as None. Everything else is standard: negative starts count from the end, end = -2 genuinely means "up to but not including the second-to-last", and a step of 2 takes every other item.

    And unlike πŸ“‹ Array Get Item, out-of-range values don't raise. Python slicing clamps, so asking for items 100–120 of a 10-item list returns an empty array and Count = 0 rather than an error. Convenient while you're experimenting, mildly treacherous when a batch silently comes back empty.

    Inputs and outputs

    Array is socket-only - the pack marks it force_input, so there's no text box to paste into. Wire it in from πŸ“‚ List Files, πŸ“‹ Array From Text, or πŸ“‹ Array Filter.

    Start, End, Step are the three integers that define the window. Start is inclusive; End is exclusive; -1 means "run to the end". Step of 1 is what you want 95% of the time; 2 or 3 is for building an evenly-sampled subset of a big list (every third caption, say) without random deletion.

    Trim Items on by default keeps the returned lines clean.

    Outputs are Array and Count - the same pair every array producer in this pack emits, which means slices chain: slice 0–100, then slice 20–40 out of that, and the second node's Count tells you whether the first one did what you thought.

    A concrete use

    Filenames from πŸ“‚ List Files β†’ πŸ“‹ Array Filter with *.png β†’ πŸ“‹ Array Slice at 0 to 50 β†’ the rest of your chain (hash them, move them, convert them). Next session, bump Start to 50 and End to 100. That's a resumable batch job built out of three nodes and an integer, which is roughly what people pay for in other ecosystems.

    For prompt banks it's the same trick in miniature: slice out a week's worth of prompts from a text file, and you're generating from a different chunk every seven days without maintaining a second file.

    Install

    Extensions β†’ Node Pack β†’ search "Honda Nodes" β†’ Install in Manager, or:

    cd ComfyUI/custom_nodes
    git clone --depth 1 https://github.com/Avaray/honda-nodes.git
    cd honda-nodes
    python install.py    # ComfyUI's python; portable Windows: ..\..\..\python_embeded\python.exe install.py
    

    Array nodes need none of the downloaded binaries, but the pack's JSON and metadata nodes do, so the install step is worth running once. Requirements worth flagging: ComfyUI 0.38.0 or newer - the whole pack is V3-schema only.

    Common issues

    Count is 0. Either the window is past the end of the list, or Start is greater than End. Remember End is exclusive: 0 to 10 gives you ten items, indices 0–9, not eleven.

    I asked for the last 20 and got fewer. With end = -1 you get to the end; with start set to something like -20 and end = -1 you get the last twenty - unless the list is shorter than twenty, in which case you get all of it. That's correct behavior, and it's why Count is worth checking before you feed the result into a loop.

    Nothing executes. Non-output nodes only run when something downstream needs them. If your slice output goes nowhere, the node never fires and Count stays stale.

    Category⚑️ Honda Nodes/πŸ“‹ Array

    Inputs (5)

    NameTypeDefaultDescription
    arraySTRINGNewline-separated array string.
    startINT0Inclusive start index. Supports negative indices.
    endINT-1Exclusive end index. Use -1 for the end of the array.
    stepINT1Step between items in the slice.
    trim_itemsBOOLEANtrueStrip leading and trailing whitespace from each item.

    Outputs (2)

    NameTypeDescription
    ArraySTRINGβ€”
    CountINTβ€”