Nodes/ComfyUI-ArchiGraph/Iterate Generator πŸ¦β€πŸ”₯
ComfyUI Node

Iterate Generator πŸ¦β€πŸ”₯

Walk a whole folder through your pipeline, one pass at a time

By vincentfsΒ·Created 2 years agoΒ·Updated 9 months agoΒ· 3
Iterate Generator πŸ¦β€πŸ”₯
  • generatorMaker
  • item
  • index
β—„enabledtrueβ–Ί

Iterate Items loops over a list you've already built in the graph. This node loops over a generator - and in this pack, that means it's the consuming half of the folder-batch pipeline: Filepath Generator Maker builds a lazy walk over every file in a folder, and this node feeds you one file path per run while the workflow re-executes itself. It's the difference between dragging a hundred files in by hand and pointing at a folder.

How it works - the same queue trick

Under the hood it's the same mechanism as the pack's Iterate Items: the node keeps an internal counter, returns the next item, and re-enqueues the currently running workflow with a fresh prompt id so ComfyUI runs the whole graph again. Each pass you get the next file. When the generator is exhausted, it resets to 0 and returns (None, 0) - without re-queueing - so the loop stops cleanly.

The generatorMaker input takes the *-typed enumerator output of Filepath Generator Maker. Don't feed it a plain list - it expects something callable that returns a generator, and that's exactly what the Maker hands you.

The enabled toggle

The one behavioral knob is enabled (default true). Turn it off and the node short-circuits - returns (None, 0) and stops iterating, even mid-run. That's your pause switch: disable it to run the rest of the graph once without the loop taking over, or to halt a long folder batch without deleting nodes. It also doubles as a safety: if you want the loop off while you rebuild the downstream graph, flip this instead of disconnecting wires.

Outputs

item (* - whatever the generator yields, here a file path) and index (INT, 0-based, and it's the current index before incrementing). Use index to name per-file outputs so pass 47 doesn't overwrite pass 46. In the typical chain, item feeds a Load Image (or this pack's Nparray Load), the pipeline processes, and a save node uses index in the filename.

Install

ComfyUI Manager β†’ search ComfyUI-ArchiGraph, or:

cd ComfyUI/custom_nodes
git clone https://github.com/vincentfs/ComfyUI-ArchiGraph

Restart and run the pack's install script once. Pure Python - no OpenCV needed for this node.

Gotchas

  • It's a full-graph loop: every pass re-runs everything connected anywhere in the workflow, including save nodes. Keep heavy outputs where you can, or accept N saves.
  • State lives on the node instance. Changing the folder or file count mid-run can leave the counter somewhere unexpected; restart the queue cleanly when you change inputs.
  • If you plug something that isn't a generator factory into generatorMaker, you'll get a TypeError at execution - the Maker's output is the intended pairing.

Folder batch processing, cleanly: Maker β†’ Iterate Generator β†’ process β†’ save per index. It's the node that makes the pack's whole "process a directory" story work.

CategoryπŸ¦β€πŸ”₯ ArchiGraph/πŸ› οΈ Utils

Inputs (2)

NameTypeDefaultDescription
generatorMaker*Input a generator to iterate
enabledBOOLEANtrueOnly run when enabled.

Outputs (2)

NameTypeDescription
item*β€”
indexINTβ€”