Add flow selection nodes

This commit is contained in:
StableLlama
2025-05-18 16:33:41 +02:00
parent e1ee38fe0d
commit e0643e885e
2 changed files with 79 additions and 1 deletions
@@ -1,6 +1,8 @@
from typing import Any
from inspect import cleandoc
from comfy.comfy_types.node_typing import IO, ComfyNodeABC
from comfy_execution.graph import ExecutionBlocker
class IfElse(ComfyNodeABC):
"""
@@ -218,10 +220,42 @@ class ExecutionOrder(ComfyNodeABC):
return (None,)
class FlowSelect(ComfyNodeABC):
"""
Select the direction of the flow.
This node takes a value and directs it to either the "true" or "false" output.
Note: for dynamic switching in a Data Flow you might want to use
"filter select" instead.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"value": (IO.ANY, {}),
"select": (IO.BOOLEAN, {}),
}
}
RETURN_TYPES = (IO.ANY, IO.ANY)
RETURN_NAMES = ("true", "false")
CATEGORY = "Basic/flow control"
DESCRIPTION = cleandoc(__doc__ or "")
FUNCTION = "select"
def select(self, value, select = True) -> tuple[Any, Any]:
if select:
return value, ExecutionBlocker(None)
else:
return ExecutionBlocker(None), value
NODE_CLASS_MAPPINGS = {
"Basic data handling: IfElse": IfElse,
"Basic data handling: IfElifElse": IfElifElse,
"Basic data handling: SwitchCase": SwitchCase,
"Basic data handling: FlowSelect": FlowSelect,
"Basic data handling: ExecutionOrder": ExecutionOrder,
}
@@ -229,5 +263,6 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"Basic data handling: IfElse": "if/else",
"Basic data handling: IfElifElse": "if/elif/.../else",
"Basic data handling: SwitchCase": "switch/case",
"Basic data handling: FlowSelect": "flow select",
"Basic data handling: ExecutionOrder": "force execution order",
}