Nodes/Shima/Shima String Switch
ComfyUI Node

Shima String Switch

Pick one of eight strings by index, and keep the rest as bonus outputs

By KDB-USJP·Created 6 months ago·Updated 6 months ago· 2
Shima String Switch
    • SELECTED
    • ALL_CSV
    • ALL_TUPLE
    • ALL_DICT
    index1
    string_1
    string_2
    string_3
    string_4
    string_5
    string_6
    string_7
    string_8

    A switch is the graph's version of an if-statement: pick one input, pass it through. Shima StringSwitch is that idea for strings - eight optional string_1string_8 inputs, one index widget (1–8), and the selected string comes out the SELECTED port. It's the same routing valve you get in a dozen other packs, with one difference: it also hands you the whole set in three other shapes.

    Those extra outputs are why you'd pick this over a generic switch. ALL_CSV gives you every connected string comma-joined - handy for dumping the full set into a log or filename. ALL_TUPLE is the same values as a Python tuple for any node that eats lists. ALL_DICT is a dict keyed 18 with only the connected entries, which is the most useful of the three for scripting-style nodes that address strings by slot. Unconnected inputs are skipped everywhere, so the outputs always reflect what's actually wired, not a padded 8-slot structure.

    The inputs

    • index - the selector, 1 through 8, default 1. Wire it from a counter or a UI node and you've turned the switch into a sequential router; drive it from a seed and it becomes a random-ish picker.
    • string_1string_8 - all optional, all forced as inputs (they can't be turned into widgets). At least one should be connected, obviously.

    Output: SELECTED (the string at index), plus ALL_CSV, ALL_TUPLE, ALL_DICT.

    How it behaves

    Selection is a plain dict lookup on the connected inputs: strings.get(index, ""). That default matters - if index points at a slot you left unconnected, SELECTED is an empty string, not an error and not the first connected value. Silent, but predictable once you know it. There's no fallback logic here; this is the A/B-switch shape, not the first-non-null shape. If you want "give me whichever one is connected," that's a different node (rgthree's Any Switch and its ilk), and this isn't it.

    Installing it

    Part of KDB-USJP/shima_wf:

    cd ComfyUI/custom_nodes
    git clone https://github.com/KDB-USJP/shima_wf
    

    Restart ComfyUI. No extra dependencies.

    The honest take

    For pure single-string routing, any switch does this and you don't need the pack. The reason to reach for this one is the trio of aggregate outputs - if your workflow is the kind that wants the selected prompt and the full list as a CSV for a log, that's all in one node here, which beats stringing together a switch, a concat, and a couple of primitives. Two gotchas to remember: index is 1-based (everyone hits "why is it off by one" once), and pointing at an empty slot silently yields "". Keep those in mind and it's a reliable little router.

    CategoryShima/Utilities

    Inputs (9)

    NameTypeDefaultDescription
    indexINT11–8
    string_1optSTRING
    string_2optSTRING
    string_3optSTRING
    string_4optSTRING
    string_5optSTRING
    string_6optSTRING
    string_7optSTRING
    string_8optSTRING

    Outputs (4)

    NameTypeDescription
    SELECTEDSTRING
    ALL_CSVSTRING
    ALL_TUPLETUPLE
    ALL_DICTDICT