Tutorial 3 ‐ Concatenate Hello World - Suzie1/ComfyUI_Guide_To_Making_Custom_Nodes GitHub Wiki
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.
nodes.py
file in Notepad++ or an IDE
1. Open the - Windows Notepad is not recommended.
2. Setup the class structure
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
5. Add the input parameters into the class structure
- 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"}),
}
}
8. Add the main function into the class structure
- 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
11. Check the completed node
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,)
__init__.py
file
Add the node to the __init__.py
file
1. Add a class mapping for the Hello World node in the "Concatenate Hello World": ConcatenateHelloWorld,
__init__.py
file
2. Check the updated 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")