ComfyUI Extension: ComfyUI Switch Any Node
This is a custom node for ComfyUI that provides a dynamic 'Switch' for routing purposes. It allows you to define a list of named labels and select one, outputting the corresponding index and label name. This is useful for controlling the flow of your workflow based on a selection.
Custom Nodes (0)
README
ComfyUI Switch Any Node
This is a custom node for ComfyUI that provides a dynamic "Switch" for routing purposes. It allows you to define a list of named labels and select one, outputting the corresponding index and label name. This is useful for controlling the flow of your workflow based on a selection.
Features
- Dynamic Label Inputs: Start with a single label input. As you fill them in, new empty inputs appear automatically after a refresh.
- UI Refresh Button: A "Save & Refresh UI" button is included directly on the node. This saves your current labels and reloads the ComfyUI interface in one click, updating the dropdown menu and input fields instantly.
- No Data Input: This node is purely for routing and does not take any data inputs. It only outputs the selected
index
(INT) andlabel
(STRING). - Persistent Labels: Your list of labels is saved in a JSON file within the node's directory, so they persist across ComfyUI sessions.
How to Use
- Add the Node: Add the
Switch Any
node to your workflow. - Define Labels:
- Initially, you will see one input field,
label_1
. Enter a name for your first route (e.g., "SDXL"). - To add more labels, you can fill in the next available input field (
label_2
, etc.).
- Initially, you will see one input field,
- Save and Refresh:
- Click the "Save & Refresh UI" button on the node.
- The page will automatically reload.
- Select a Label:
- After reloading, the
select_label
dropdown menu will be populated with all the labels you defined. - The node will now show all your saved labels plus one new empty input field for the next one.
- After reloading, the
- Get Output: The node will output the 1-based
index
and thelabel
string of your selection from the dropdown menu.
Installation
- Clone or download this repository.
- Place the
ComfyUI_Switch
folder into theComfyUI/custom_nodes/
directory. - Restart ComfyUI.
ComfyUI Switch Any 节点 (中文说明)
这是一个为 ComfyUI 设计的自定义节点,提供了一个用于路由目的的动态“切换”功能。它允许您定义一个带名称的标签列表并从中选择一个,然后输出对应的索引和标签名。这对于根据选择来控制您的工作流非常有用。
功能特性
- 动态标签输入: 从一个标签输入框开始。当您填写后,刷新界面即可自动出现新的空输入框。
- UI 刷新按钮: 节点上直接集成了一个 "Save & Refresh UI" 按钮。一键即可保存当前所有标签并重新加载 ComfyUI 界面,即时更新下拉菜单和输入框。
- 无数据输入: 这是一个纯粹的路由节点,不接收任何数据输入。它只输出所选的
index
(整数) 和label
(字符串)。 - 标签持久化: 您的标签列表会保存在节点目录下的一个 JSON 文件中,因此可以在不同的 ComfyUI 会话之间保持不变。
如何使用
- 添加节点: 在工作流中添加
Switch Any
节点。 - 定义标签:
- 最初,您会看到一个输入框
label_1
。为您的第一个路由输入一个名称 (例如 "SDXL")。 - 要添加更多标签,只需填写下一个可用的输入框 (
label_2
等) 即可。
- 最初,您会看到一个输入框
- 保存并刷新:
- 点击节点上的 "Save & Refresh UI" 按钮。
- 页面将会自动重新加载。
- 选择标签:
- 重新加载后,
select_label
下拉菜单中将填充您定义的所有标签。 - 节点现在会显示所有已保存的标签,并额外提供一个新的空输入框供您继续添加。
- 重新加载后,
- 获取输出: 节点将输出您从下拉菜单中所选项的
index
(从1开始的整数) 和label
(字符串)。
安装方法
- 克隆或下载此仓库。
- 将
ComfyUI_Switch
文件夹放入ComfyUI/custom_nodes/
目录下。 - 重启 ComfyUI。