Nodes/ComfyUI-0246/Script Rule
ComfyUI Node

Script Rule

Tells the Script how to sweep its inputs

By Trung0246·Created 3 years ago·Updated about a year ago· 137
Script Rule
    • script_rule_data
    script_rule_mode

    Script Rule is the smallest piece of the 0246 pack's "execute anything" trio, and its whole job is deciding how the Script node walks across its inputs. A ScriptNode says what to run. A ScriptRule says in what pattern to run it - once, zipped, or every-combination.

    It's a deliberately tiny node: one enum input, one SCRIPT_DATA output. You wire its output into a Script node alongside the scripted node's data, and the rule becomes the driver loop for the execution. If you're only running a scripted node once per queue, you don't strictly need it - but the moment you want to sweep a batch of seeds or a grid of parameters through one scripted sampler, this is the knob.

    The one input that matters

    script_rule_mode has three choices, and they map to three different iteration strategies:

    • _ (the underscore, default when connected) - direct: run the exec function once with all pins as-is. No iteration.
    • slice - zip: if a pin holds a list, walk it element-by-element alongside every other list pin. [10, 20] and [100, 200] → runs (10, 100) then (20, 200). Lists must match length, conceptually.
    • cycle - cartesian product: run the exec function once for every combination of list elements. [10, 20] × [100, 200] → four runs. This is your parameter-grid mode.

    Under the hood these map to three driver functions in the pack's source - script_rule_direct, script_rule_slice, script_rule_product - which call the scripted node's exec function with each slice or product of the pins. The results are collected in order and come out of the Script node as batches.

    The output

    script_rule_data - a SCRIPT_DATA packet of kind: "rule". Wire it into a Script node's input. That's the entire contract.

    How to install it

    The usual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Trung0246/ComfyUI-0246
    

    restart, or ComfyUI Manager → search "ComfyUI-0246". No models.

    Common issues & troubleshooting

    The rule appears to do nothing. With _, that's correct - direct mode runs once. If you expected iteration, switch to slice or cycle.

    slice errors or skips data. Slicing assumes your list pins zip together; unequal lengths behave inconsistently, so keep the pins' list lengths aligned. If you genuinely need ragged combinations, cycle is the safer mode.

    Outputs come back as one big batch. Also correct - the rule drives multiple executions and Script transposes the results into lists. Unpack them per-run with a Hold or a list-slice node. And the usual pack caveat: single-author, dormant since early 2025 - test the script system against your ComfyUI version before you build a workflow that leans on it.

    Category0246

    Inputs (1)

    NameTypeDefaultDescription
    script_rule_modeCOMBO3 options: _, slice, cycle

    Outputs (1)

    NameTypeDescription
    script_rule_dataSCRIPT_DATA