Slice Panels List
Subset a list of panels with Python slice syntax
- panels
- POLYGON
Slice Panels List is a small list-handling utility that punches above its weight once you're assembling a real page. It takes the list of panel polygons that Build Layout Panels outputs and subsets it with Python slice syntax - so you can grab every other panel, reverse the list, or cut off the last panel, all without juggling index nodes.
The input you'll actually type into is _slice, a string field that speaks Python: 0:5 (first five), 2: (from index 2 on), ::-1 (reversed), 1:8:2 (every other panel in a range), or a plain 3 to pull a single index. Default is 0:, which is the identity - the whole list passes through. It also handles negative indices and steps, so -3: grabs the last three panels.
- panels - the list of polygons (the node takes a list and gives you a list back).
_slice- the slice expression string.
Output is a POLYGON list - just the selected panels, in the selected order.
Why you'd use it mid-pipeline rather than at the end: panel lists in this pack are ordered by reading order, which is convenient for building pages but not for every operation. Reversing the list ([::-1]) is a quick way to flip between left-to-right and right-to-left page assembly. Slicing lets you process only some panels through an expensive per-panel generation branch while the rest go a cheaper route - say, "generate the splash panel at high res, the rest at base res" by slicing panel 0 out, handling it specially, and re-merging later with the pack's list nodes.
The mechanism is deliberately simple: it validates your slice string against a strict regex (so garbage like 1::: just errors instead of doing something weird), parses it into a Python slice object, and applies it to a deep copy of the list. The deep copy is a nice touch - you never accidentally mutate the original list for the rest of the graph.
The one sharp edge: this is a list-order operation, and the order is whatever the upstream node produced. If you reordered panels elsewhere, the slice applies to that order, not to reading order. Keep your panel list canonical and slice where you need it, rather than trying to reconstruct order after slicing. Also, a single-index slice returns a list of one, not a bare polygon - it's list-in, list-out by design, so your downstream list consumers don't break.
Installing
Part of comfyui-panels by bmad4ever. Via ComfyUI Manager (search "comfyui-panels") and restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_panels
Deps: shapely, matplotlib, opencv-python - no models, no GPU. Shapely is pinned exactly; version clashes with other packs are the realistic import failure.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| panels | POLYGON | — | |
| _slice | STRING | 0: | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| POLYGON | POLYGON | Panels (Shapely Polygons) |