Nodes/Kinburg-Nodes/Get by Index
ComfyUI Node

Get by Index

Pull one frame out of anything, without the slicing math

By Kinburg·Created 3 months ago·Updated 6 days ago· 1
Get by Index
  • value
  • item
  • length
index0
out_of_rangeclamp

Core ComfyUI is weirdly bad at one basic thing: grabbing a single item out of a batch. You can't just right-click and keep frame 4 - you need slicing nodes, or arithmetic, or a trip through a list node that may or may not keep the tensor shape valid. Get by Index is the version that just works, and it works on anything: an IMAGE or MASK batch, a LATENT batch, a Python list, a string. Feed it value and an index, get the item back.

The mechanism is where it earns its keep, because it handles the type cases that usually bite people. For media tensors it keeps the batch dimension - an IMAGE batch of [B, H, W, C] returns a one-frame batch ([1, H, W, C]), not a squeezed array, so the item is still a valid IMAGE type that every downstream image node accepts. Same for LATENT dicts: it slices the samples tensor and keeps the dict wrapper, so the item stays a valid LATENT. Lists, tuples and strings return a plain element. The one genuinely un-indexable thing (a scalar) passes through unchanged. There's no type juggling on your end.

The inputs are small and worth reading, because the index handling is friendlier than Python's:

  • value - anything indexable. The tooltip's list is the contract: "an IMAGE/MASK batch, a LATENT batch, a list, a string, etc."
  • index - element to take; negative counts from the end, so -1 is the last frame. The source resolves negatives by adding the length, same as Python.
  • out_of_range - what happens past the end: clamp (nearest valid index, the default), wrap (modulo, so it cycles), or error (stops the run). Clamp is the forgiving default; error is there when a silent wrong frame would be worse than a loud crash.

Outputs are item (the element, correct type for what went in) and length - the container's length, which is a genuinely useful freebie if you're wiring up a loop or a repeat whose iteration count depends on the batch size.

Installing

Ships in Kinburg-Nodes: ComfyUI Manager → search "Kinburg-Nodes", or:

cd ComfyUI/custom_nodes
git clone https://github.com/Kinburg/Kinburg-Nodes
# restart ComfyUI

No dependencies beyond ComfyUI's bundled torch. It lives in the flow/loops package next to the For Each family, but it's not loop-only - "pull frame 4 out of this batch and upscale it alone" is a perfectly standalone use.

Gotchas

clamp is the default and it means a wrong index never tells you it was wrong - index 99 on a 10-frame batch quietly hands you frame 9. If you're debugging why a specific frame came out wrong, switch to error once so the run stops where the index is bad. And remember the one-frame-batch behavior: the item keeps its batch dimension, which is what makes it valid IMAGE/LATENT output, but it means the "single frame" is technically a batch of one. Most nodes won't care; the ones that do (like a VAE decode) will happily decode a batch of one.

CategoryKinburg-Nodes/flow/loops

Inputs (3)

NameTypeDefaultDescription
value*Anything indexable: an IMAGE/MASK batch, a LATENT batch, a list, a string, etc.
indexINT0-100000–100000Element to take. Negative counts from the end (-1 = last).
out_of_rangeCOMBOclampIndex past the end: clamp = nearest valid, wrap = modulo (cycle), error = stop the run.

Outputs (2)

NameTypeDescription
item*
lengthINT