From cc6196c25f08a467168eb0d2b0f385dee62ef524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20=20Sk=C3=B6ld?= Date: Sun, 4 Aug 2024 14:44:20 +0200 Subject: [PATCH] Change WidgetToString to use the any_input link if no id or title. If no node if or title is provided use the link to get the node id. --- nodes/nodes.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/nodes/nodes.py b/nodes/nodes.py index 82dd3e6..7d5b2ce 100644 --- a/nodes/nodes.py +++ b/nodes/nodes.py @@ -711,17 +711,17 @@ class WidgetToString: def INPUT_TYPES(cls): return { "required": { - "id": ("INT", {"default": 0}), "widget_name": ("STRING", {"multiline": False}), "return_all": ("BOOLEAN", {"default": False}), }, "optional": { "any_input": (any, {}), + "id": ("INT", {"default": 0}), "node_title": ("STRING", {"multiline": False}), }, - "hidden": {"extra_pnginfo": "EXTRA_PNGINFO", - "prompt": "PROMPT"}, + "prompt": "PROMPT", + "unique_id": "UNIQUE_ID",}, } RETURN_TYPES = ("STRING", ) @@ -729,14 +729,14 @@ class WidgetToString: CATEGORY = "KJNodes/text" DESCRIPTION = """ Selects a node and it's specified widget and outputs the value as a string. +If no node id or title is provided it will use the 'any_input' link and use that node. To see node id's, enable node id display from Manager badge menu. Alternatively you can search with the node title. Node titles ONLY exist if they are manually edited! -The 'any_input' is purely for making sure the node you want the value from exists in the workflow, -it has no other function than place this node at right spot in the workflow execution order. +The 'any_input' is required for making sure the node you want the value from exists in the workflow. """ - def get_widget_value(self, id, widget_name, extra_pnginfo, prompt, return_all=False, any_input=None, node_title=""): + def get_widget_value(self, widget_name, extra_pnginfo, prompt, unique_id, return_all=False, any_input=None, id=0, node_title=""): workflow = extra_pnginfo["workflow"] #print(json.dumps(workflow, indent=4)) results = [] @@ -750,9 +750,15 @@ it has no other function than place this node at right spot in the workflow exec break else: print("Node title not found.") - elif node["id"] == id: - node_id = id - break + elif id != 0: + if node["id"] == id: + node_id = id + break + elif any_input: + if node["type"] == "WidgetToString" and node["id"] == int(unique_id): + for node_input in node["inputs"]: + node_id = node_input["link"] + break if node_id is None: raise ValueError("No matching node found for the given title or id") @@ -765,9 +771,9 @@ it has no other function than place this node at right spot in the workflow exec v = str(values["inputs"][widget_name]) # Convert to string here return (v, ) else: - raise NameError(f"Widget not found: {id}.{widget_name}") + raise NameError(f"Widget not found: {node_id}.{widget_name}") if not results: - raise NameError(f"Node not found: {id}") + raise NameError(f"Node not found: {node_id}") return (', '.join(results).strip(', '), ) class DummyOut: