-
Notifications
You must be signed in to change notification settings - Fork 8
Tutorial 3 ‐ Concatenate Hello World
Akatsuzi edited this page Dec 5, 2023
·
9 revisions
In this tutorial, we are going to build the Concatenate Hello World node below
The node concatenates two text strings and outputs these as a combined string.
- Windows Notepad is not recommended.
class ConcatenateHelloWorld:
@classmethod
def INPUT_TYPES(cls):
RETURN_TYPES = ("STRING",)
FUNCTION = "concatenate_text"
CATEGORY = "Tutorial Nodes"
def concatenate_text(self, text1, text2):
return {}
- RETURN_TYPES defines the output types
- FUNCTION is used to specify the main function
- CATEGORY specifies where the node will be included in the ComfyUI node menu
- The first parameter in the main function should always be self
- The return statement is used to specify the objects that are passed to the node outputs
- The input parameters must match the parameters in the
concatenate_text
function
return {"required": {
"text1": ("STRING", {"multiline": False, "default": "Hello"}),
"text2": ("STRING", {"multiline": False, "default": "World"}),
}
}
- In this case the function consists of a text formula.
- Python is fussy about indents. Take care to use precise indentation.
text_out = text1 + " " + text2
It should look like this:
class ConcatenateHelloWorld:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"text1": ("STRING", {"multiline": False, "default": "Hello"}),
"text2": ("STRING", {"multiline": False, "default": "World"}),
}
}
RETURN_TYPES = ("STRING",)
FUNCTION = "concatenate_text"
CATEGORY = "Tutorial Nodes"
def concatenate_text(self, text1, text2):
text_out = text1 + " " + text2
return (text_out,)
"Concatenate Hello World": ConcatenateHelloWorld,
It should look like this:
from .nodes.nodes import *
NODE_CLASS_MAPPINGS = {
"Print Hello World": PrintHelloWorld,
"Concatenate Hello World": ConcatenateHelloWorld,
}
print("\033[34mComfyUI Tutorial Nodes: \033[92mLoaded\033[0m")