comfyui节点编写示例文件(上)

文章详细描述了一个Python类的结构,涉及类方法如INPUT_TYPES用于定义节点输入配置,可选方法IS_CHANGED控制节点重执行,以及节点的属性如RETURN_TYPES、FUNCTION、OUTPUT_NODE和CATEGORY。实例展示了如何处理不同类型输入和输出,以及节点在用户界面中的组织方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

class Example:
    """
    A example node

    Class methods  # 类方法
    -------------
    INPUT_TYPES (dict):  # 告诉主程序输入节点参数。
        Tell the main program input parameters of nodes.  
    IS_CHANGED:  # 这个类方法是可选的,控制何时重新执行节点的可选方法。
        optional method to control when the node is re executed.  

    Attributes
    ----------
    RETURN_TYPES (`tuple`):  #  输出元组中每个元素的类型 
        The type of each element in the output tulple.
    RETURN_NAMES (`tuple`):  # 可选属性,为输出元组中的每个元素提供描述性名称。
        Optional: The name of each output in the output tulple.
    FUNCTION (`str`):  # 入口方法的名称
        The name of the entry-point method. For example, if `FUNCTION = "execute"` then it will run Example().execute()
    OUTPUT_NODE ([`bool`]):  # 如果此节点是输出节点,则从图中输出结果/图像
        If this node is an output node that outputs a result/image from the graph. The SaveImage node is an example.
        The backend iterates on these output nodes and tries to execute all their parents if their parent graph is properly connected.
        Assumed to be False if not present.
    CATEGORY (`str`):  # 节点在用户界面中应该出现的类别。这有助于用户根据功能查找和组织节点。
        The category the node should appear in the UI.
    execute(s) -> tuple || None:  # 入口方法。该方法的名称必须与 FUNCTION 属性的值相同。
        The entry point method. The name of this method must be the same as the value of property `FUNCTION`.
        For example, if `FUNCTION = "execute"` then this method's name must be `execute`, if `FUNCTION = "foo"` then it must be `foo`.
    """
    def __init__(self):
        pass
    
    @classmethod
    def INPUT_TYPES(s):
        """
            Return a dictionary which contains config for all input fields.  # 这个函数的作用的返回一个字典,其中包含所有输入字段的配置。 
            Some types (string): "MODEL", "VAE", "CLIP", "CONDITIONING", "LATENT", "IMAGE", "INT", "STRING", "FLOAT".  
            # 部分类型(字符串):“MODEL”、
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值