Nodes/ComfyUi-MpiNodes/Mpi String Inverted Switch
ComfyUI Node

Mpi String Inverted Switch

Send one string down exactly one of five wires

By MadPonyInteractive·Created 11 months ago·Updated 5 days ago· 3
Mpi String Inverted Switch
    • str_1
    • str_2
    • str_3
    • str_4
    • str_5
    • index
    input
    select1

    Most switch nodes pick one input out of many - five candidate values in, the selected one out. MpiStringInvSwitch is the inverted shape: one string in, up to five outputs, and the select index decides which single output gets the value. The other four outputs are blocked with an ExecutionBlocker, so nothing downstream of them runs.

    That inversion is exactly what you want when the value is the same but the destination is what varies. Say you have a style tag that should reach one of five different prompt builders depending on which branch of the graph is live. A normal switch forces you to route the five builders into it; this node lets you place it first and fan the same string out to whichever branch you chose. The tooltip spells it out: select is 1–5, and the output index is also 1–5.

    How it works

    The implementation is dead simple, which is why it's reliable:

    def use_selected(self, input, select):
        ret = []
        for i in range(1, 6):
            if i == select:
                ret.append(input)
            else:
                ret.append(ExecutionBlocker(None))
        return tuple(ret)
    

    Selected output gets the string, the rest get an ExecutionBlocker - and a blocked socket means that whole downstream branch simply doesn't execute. It also outputs index (the INT of your selection) as a convenience if something downstream wants to know which branch fired.

    Install

    Ships in ComfyUi-MpiNodes. ComfyUI Manager (search "MpiNodes" / publisher "mad-pony-interactive"), or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MadPonyInteractive/ComfyUi-MpiNodes
    

    Restart. No extra dependencies or models.

    Where people get confused

    The most common surprise is the blocking behavior. People wire all five outputs to the same downstream node and expect the string to just... appear on whichever one they picked. It does - but the other four are dead branches, and if you've wired them to something that must run, it won't. That's the feature, not a bug; if you wanted a value to reach several outputs at once, you want a reroute or a splitter, not an inverted switch. Also note this is the string-typed version - the pack's MpiAnyInvSwitch is the same shape but accepts any type (*), so if the value isn't a string, that's the one you want. The select index is 1-based, not 0-based; off-by-one is the classic oops here, and the index output exists partly so you can log which branch actually fired.

    CategoryMpiNodes/Logic

    Inputs (2)

    NameTypeDefaultDescription
    inputSTRING
    selectINT11–5Selection from 1 to 5 Output index is also 1 to 5

    Outputs (6)

    NameTypeDescription
    str_1STRING
    str_2STRING
    str_3STRING
    str_4STRING
    str_5STRING
    indexINT