βοΈ CR Set Switch From String
Drive an input switch with a keyword
- switch
- show_help
ComfyUI's input-switch nodes let you pick one of several branches with a number - 1 for this path, 2 for that one. CR Set Switch From String lets you pick that number with a word instead. You give it a text value and up to four labels; it finds which label the text matches and outputs that slot's index, which you feed straight into a switch node. It turns "switch to branch 2" into "switch to the branch called portrait," which is a lot easier to reason about and to drive from other text in your graph.
The reason this matters: routing logic keyed off a keyword is far more maintainable than routing keyed off a bare integer. If your workflow already has a string floating around - a mode name, a preset label, a value pulled from a prompt - this node converts it into the control signal a switch understands, so your branching follows your text instead of a magic number you have to remember.
How it works
You provide text and up to four comparison strings, switch_1 through switch_4. The node compares text against each and outputs the index of the one it matches - match switch_2 and you get 2. That integer goes into the select input of a switch node (like CR Text Input Switch (4 way), or any of the input-switch family), which then passes through the branch you named. In effect it's a string-to-route lookup: label your branches, and pick them by label.
The inputs and outputs that matter
text- the string to test. Wire it from wherever your mode/keyword comes from, or type it.switch_1βswitch_4(optional) - the labels to match against, one per branch. Set the ones you're using.
Outputs:
switch(INT) - the index of the matched label. Wire it into a switch node's select input.show_help- wiki link, ignore.
How to install it
Comfyroll Studio (Suzie1 and RockOfFire), a mature utility pack - no models, no heavy dependencies.
- ComfyUI Manager - search Comfyroll Studio, install, restart.
- Manual -
cd ComfyUI/custom_nodes && git clone https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes.git, then restart.
Also on CivitAI.
Common issues
String matching is exact, so this is where mistakes hide. Portrait won't match portrait, and a stray trailing space in either the text or a switch_ label will quietly break the match - and a text that matches none of the labels leaves you with a default index that may not be the branch you wanted. Keep your labels tidy, feed clean text, and if routing goes sideways, print or preview the actual string first to see exactly what's being compared. Treat the labels like an enum: define them once, reference them consistently.
And the pack-level one: if the node doesn't appear, check the log for Comfyroll Studio: Failed to load ... and NameError: name 'CR_HalftoneGrid' is not defined. That NameError is a symptom of a real import failure higher up - usually an incompatible Pillow version from another custom node - that can down the whole pack. Reinstall Pillow (pip install --upgrade --force-reinstall pillow) into ComfyUI's Python and restart.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | β | |
| switch_1opt | STRING | β | |
| switch_2opt | STRING | β | |
| switch_3opt | STRING | β | |
| switch_4opt | STRING | β |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| switch | INT | β |
| show_help | STRING | β |