The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
Add a Branch node (#16383)
AustinMrozdea870e1a366
diff --git a/comfy_extras/nodes_logic.py b/comfy_extras/nodes_logic.pyindex a1b2c2c5c..39901f30a 100644--- a/comfy_extras/nodes_logic.py+++ b/comfy_extras/nodes_logic.py@@ -83,6 +83,45 @@ class OrNode(io.ComfyNode):return io.NodeOutput(any(values.values()))+class BranchNode(io.ComfyNode):+ @classmethod+ def define_schema(cls):+ mtemplate = io.MatchType.Template("switch")+ minput = io.MatchType.Input("branch", template=mtemplate, lazy=True, optional=True)+ template = _io.Autogrow.TemplatePrefix(input=minput, prefix="branch", min=1, max=32)+ return io.Schema(+ node_id="BranchNode",+ display_name="Branch",+ category="utilities/logic",+ description="Select from connected inputs by name. Inputs can be renamed by double clicking them.",+ search_aliases=["switch", "choice", "pick"],+ is_experimental=True,+ inputs=[+ _io.Autogrow.Input("autogrow", template=template),+ io.String.Input("branch", extra_dict={"widgetType": "COMFY_BRANCH_SELECTOR"}),+ io.Array.Input("branch_names", extra_dict={"widgetType": "COMFY_BRANCH_INPUT_NAMES", "socketless": True}),+ ],+ outputs=[+ io.MatchType.Output(template=mtemplate, display_name="output"),+ ],+ )++ @classmethod+ def check_lazy_status(cls, branch, branch_names, autogrow):+ if branch not in branch_names:+ raise ValueError(f"{branch} is not included in available inputs: {branch_names}")+ key = f"branch{branch_names.index(branch)}"+ if key not in autogrow:+ raise ValueError(f"Selected input {branch} is not connected")+ return ['autogrow.' + key]++ @classmethod+ def execute(cls, branch, branch_names, autogrow) -> io.NodeOutput:+ if branch not in branch_names:+ raise ValueError(f"{branch} is not included in available inputs: {branch_names}")+ return autogrow[f"branch{branch_names.index(branch)}"],++class SwitchNode(io.ComfyNode):@classmethoddef define_schema(cls):@@ -341,6 +380,7 @@ class LogicExtension(ComfyExtension):NotNode,AndNode,OrNode,+ BranchNode,# SoftSwitchNode,# ConvertStringToComboNode,# DCTestNode,