Nodes/Mask Analyzer/Mask Strategy Switch
ComfyUI Node

Mask Strategy Switch

Turn a strategy string into a number your graph can route on

By imk-design·Created 5 months ago·Updated 5 months ago· 0
Mask Strategy Switch
    • selected_value
    strategydirect
    direct_value0
    simplified_value1
    overlay_value2

    This is the tiny sibling of Mask Analyze, and it does exactly one thing: take a strategy string - direct, simplified, or overlay - and map it to an integer you choose. By default that's 0, 1, and 2.

    Why bother? Strings are awkward to branch on inside a ComfyUI graph. There's no clean if string == "overlay" in node land; there's plenty of stuff that eats an INT. So instead of writing your own string-matching logic, you let Mask Analyze classify the mask, feed the strategy string in here, and push the integer out to whatever downstream node needs a selector. It's the plumbing half of the pack, and it's about as simple as plumbing gets.

    How it works

    Under the hood it's a three-way lookup: lowercases the string, strips whitespace, and does an exact match. overlay returns overlay_value, simplified returns simplified_value, and anything else - including typos, unexpected text, or an empty string - falls back to direct_value. That default-to-direct behavior is deliberate and worth knowing: it's a safe failure mode, but it means a hand-typed simplifed will silently give you the direct branch rather than erroring. If you're feeding it strings manually, mind your spelling.

    Inputs and output

    • strategy (STRING, default "direct") - normally the output of Mask Analyze, or anything else you want to branch on.
    • direct_value, simplified_value, overlay_value (INT, defaults 0/1/2) - the numbers each strategy maps to. These accept negatives, so you could map to -1/0/1 if that suits a strength or offset somewhere.
    • Output: selected_value (INT).

    That's the entire interface. It does not parse, it does not validate, it does not reach for external tools.

    Where to wire it

    The most natural pairing: MASK source -> Mask Analyze -> strategy -> Mask Strategy Switch -> selected_value. From there the integer can drive a KSampler's denoise, a conditioning strength, a sampler selection, or any of the integer-driven switch and muter nodes that packs like rgthree and Impact make heavy use of. You can also use it standalone as a manual three-way selector - type the string into the strategy field and it behaves like a small, explicit switch with custom values.

    Install

    It ships in the Mask Analyzer pack, so installing it installs both nodes:

    cd /path/to/ComfyUI/custom_nodes
    git clone https://github.com/imk-design/ComfyUI-Mask-Analyzer.git
    

    Then restart ComfyUI. Or install via ComfyUI Manager by searching "Mask Analyzer". No dependencies beyond what ComfyUI already has, no model files.

    Honest take: on its own this node is almost too small to be worth installing for - you can get the same effect with an IF/switch node you already have. It earns its place only as the output half of Mask Analyze, where it turns the pack's classification into something your graph can actually act on without string comparisons everywhere.

    CategoryMask Tools

    Inputs (4)

    NameTypeDefaultDescription
    strategySTRINGdirect
    direct_valueINT0-999999–999999
    simplified_valueINT1-999999–999999
    overlay_valueINT2-999999–999999

    Outputs (1)

    NameTypeDescription
    selected_valueINT