Slice Operation
Python-style slicing, without leaving the graph
- values
- *
You know how in Python you write my_list[3:7] and get items 3 through 6? JN_SliceOperation is that, as a node. It takes a pile of values, applies one of six slice operations defined by two integers a and b, and hands back the subset. If you've ever wanted "just the first 10 frames" or "everything after item 5" without writing a custom node, this is the tool.
How it works
The pipeline is the same as the pack's other array processors: values is a dynamic multiple input (connect things and new slots appear), merge_array_items flattens any arrays into one list, only_active drops None entries, and then the slice happens. The six operations are a dropdown on the node:
[a:b]- items fromaup to (not including)b[a:a+b]-bitems starting ata[a-b:a]-bitems ending just beforea[a-b:a+b]-bitems on each side ofa[a:]- everything fromato the end[:a]- everything from the start up to (not including)a
These are real Python slice semantics, which means negative numbers work the way you'd hope: a=-3 with [:a]... actually [-3:] isn't in the list, but a=-3 in [a:] gives you the last three items, and [a:b] with negatives counts from the end. If a and b are both 0 you get an empty slice, so watch that default.
The output is a * that carries the sliced list, not a single item. That trips people up - a slice of a 12-item list is still a list.
Inputs that matter
- a, b - the two integers. You can wire math nodes into these for dynamic ranges, e.g. "take the next N items" with N computed elsewhere.
- operation - the six-way dropdown; this is what you'll actually fiddle with most.
only_activeandmerge_array_items- same semantics asJN_SelectItem: indexes count connected values only, and arrays get flattened first.- values - the dynamic input pile.
Where you'd use it
Anywhere you process batches or sequences. Grab the first N frames of a video workflow. Chop the leading junk off a batch of images. Take a middle window out of an array and re-slice it to iterate over it. Because a and b can be computed, it slots neatly next to JN_MathOperation for "give me a sliding window" patterns - compute the window start, feed it in as a, use [a:a+b] with a fixed b.
Install
It's part of JNComfy. ComfyUI Manager → search "JNComfy" → Install, restart. Or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/jn-jairo/jn_comfyui
restart, and run pip install -r requirements.txt inside the folder if you're not using Manager. The requirements list is big (audio, vision, transformers…) but this node needs none of it - pure Python list slicing.
Gotchas
- The output is a list, not an item. If you want one thing out of the slice, chain it into
JN_SelectItem. - Slicing happens after
only_activefilters, so the positions you address are positions among connected values, not raw slot numbers - same trap as its sibling nodes. - Default
aandbare both 0, which yields an empty list on most operations. Type your numbers before you run, or you'll wonder where your data went.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| a | INT | 0-18446744073709550000–18446744073709550000 | — |
| b | INT | 0-18446744073709550000–18446744073709550000 | — |
| operation | COMBO | 6 options: [a:b], [a:a+b], [a-b:a], [a-b:a+b], [a:], [:a] | |
| only_active | BOOLEAN | true | — |
| merge_array_items | BOOLEAN | true | — |
| valuesopt | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| * | * | — |