π Array Slice
Chop a long list into batches without deleting anything
- Array
- Count
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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| array | STRING | Newline-separated array string. | |
| start | INT | 0 | Inclusive start index. Supports negative indices. |
| end | INT | -1 | Exclusive end index. Use -1 for the end of the array. |
| step | INT | 1 | Step between items in the slice. |
| trim_items | BOOLEAN | true | Strip leading and trailing whitespace from each item. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| Array | STRING | β |
| Count | INT | β |