diff --git a/README.md b/README.md index bf6993e..f266020 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ # comfyui-node-template + A simple ComfyUI node development starter template. + +## Set-up + +```py +uv init +``` + +## Node placement + +Custom node directory goes in `comfyui/custom_nodes` diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..34811a5 --- /dev/null +++ b/__init__.py @@ -0,0 +1,5 @@ +# mappings for the ComfyUI node. + +from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS + +__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"] diff --git a/execute.py b/execute.py new file mode 100644 index 0000000..23c825c --- /dev/null +++ b/execute.py @@ -0,0 +1,9 @@ +# An external class to process the `execute` + +class MyExecuteClass: + + def __init__(self): + pass + + def run(self, toggle): + return f"run output {toggle}" diff --git a/nodes.py b/nodes.py new file mode 100644 index 0000000..db97028 --- /dev/null +++ b/nodes.py @@ -0,0 +1,56 @@ +# ComfyUI node +from .execute import MyExecuteClass + +class MyComfyNode: + + # runs on load only + def __init__(self): + self.execute_class = MyExecuteClass() + + # node inputs, if any. + @classmethod + def INPUT_TYPES(cls): + return {"required": { + "prefix": ("STRING", {"default": "", "tooltip": "a prefix"}), + "slider_float": ("FLOAT", {"default": 20.0, "min": 1.0, "max": 99.0, "step": 0.5}), + "slider_int": ("INT", {"default": 5, "min": 1, "max": 20 }), + "toggle": ("BOOLEAN", {"default": False, "tooltip": "toggle me"}), + }} + + #return {} #no inputs + + # node title (visible title) + TITLE = "My ComfyUI Node" + + # not a trailing comma, is tuple. + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("output",) + + # function to run on "execute" + FUNCTION = "execute" + + # does node have an "output" + OUTPUT_NODE = True + + # node metadata + CATEGORY = "category/MyComfyNode" + DESCRIPTION = "My ComfyUI Node" + + # the node structure has changed + def IS_CHANGED(): + return float("nan") #force cache refresh + + # run the node execute method + def execute(self): + result = self.execute_class.run(self.toggle) + # return tuple + return (result,) + +# node mappings (see also __init__.py) +NODE_CLASS_MAPPINGS = { + "MyComfyNode": MyComfyNode, +} +# name mappings +NODE_DISPLAY_NAME_MAPPINGS = { + "MyComfyNode": "My ComfyUI Node" +}