ComfyUI Node

Any Length

'how big is this thing?' without caring what the thing is

By wenchengxiang·Created 2 months ago·Updated 9 days ago· 3
Any Length
  • any
  • length

One input, one output, zero setup: any in, an INT length out. Any Length tells you how big something is without you having to know what that something is ahead of time. It's the sort of utility node that looks pointless until the moment you need the batch size of an image batch and realize there's no obvious node doing that in core.

The behavior, from the source, depends on what you connect:

  • A list or tuple → its length (len()).
  • A torch tensor → the size of the first dimension (shape[0]), which is the batch count for an image or mask batch. A 0-dimensional scalar returns 1.
  • Anything else - a string, an int, even None → 1.
  • Multiple connections at once → the number of connected inputs.

So it's "length" in the collection sense, not the character-count sense. The place it earns its keep is batch plumbing: how many images am I working with, so I can number files, loop a count, or split a batch in half. Compare the output to a threshold with a node like Any Compare and you've got conditional batch routing. It's also a clean way to answer "is this a batch or a single" - the result being 1 vs > 1 is exactly that test.

Three gotchas, because each one has burned someone:

  • Strings don't give character counts. Wire "hello" in and you get 1, not 5. It measures the container, not the contents. If you want string length, this isn't the node.
  • Multiple connections return the connection count, not anything about the values. That's a side effect of how ComfyUI's list-input mode works here, and it reads as weird until you know it. Don't wire two values in expecting a meaningful sum - you'll just get 2.
  • The output is the first dimension for tensors. For a [2, 512, 512] image batch that's 2 - exactly what you want. Just remember it's shape[0], so a transposed or unusual tensor surprises you.

Install is the pack standard: ComfyUI Manager → search ComfyUI-Practical-Tools → install → restart, or git clone https://github.com/wenchengxiang/ComfyUI-Practical-Tools into ComfyUI/custom_nodes and restart. No dependencies, no models. The node itself is about as failure-proof as plumbing gets - the only realistic "issue" is expecting a character count and getting 1, which is a reading problem, not a code one.

CategoryPractical-Tools/utils

Inputs (1)

NameTypeDefaultDescription
any*—

Outputs (1)

NameTypeDescription
lengthINT—