I'm trying to create and register a new Compositor Node. The python code runs fine in the Blender console (no errors), but after I run it, nothing happens.
what I expect to happen: When I'm in the Compositor node editor, after I run my code I should be able to find my new compsitor node underneath Add>Input.
However, I can't find it.
import bpy
class InvertColorsNode(bpy.types.CompositorNode):
# Define the node identifier, name, and input/output sockets
bl_idname = "InvertColorsNode"
bl_label = "Invert Colors"
bl_socket_idname = "InvertColorsNode"
input_image = bpy.props.StringProperty(name="Image", default="")
output_image = bpy.props.StringProperty(name="Image", default="")
def init(self, context):
self.inputs.new("NodeSocketColor", "Image")
self.outputs.new("NodeSocketColor", "Image")
def update(self):
# Get the input and output images
input_image = self.inputs.get("Image").default_value
output_image = self.outputs.get("Image").default_value
# Invert the colors of the input image and store the result in the output image
#output_image=(1.0 - input_image[0], 1.0 - input_image[1], 1.0 - input_image[2])
def draw_buttons(self, context, layout):
# Add a button to the compositor node that allows the user to invert the colors of the input image
layout.operator("invert_colors.operator", text="Invert Colors")
class InvertColorsOperator(bpy.types.Operator):
# Define the operator identifier, name, and options
bl_idname = "invert_colors.operator"
bl_label = "Invert Colors"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
# Invert the colors of the input image
input_image = context.node.inputs["Image"].default_value
context.node.outputs["Image"].default_value = (1.0 - input_image[0], 1.0 - input_image[1], 1.0 - input_image[2])
return {"FINISHED"}
def register():
# Register the custom compositor node class
bpy.utils.register_class(InvertColorsNode)
bpy.utils.register_class(InvertColorsOperator)
def unregister():
# Unregister the custom compositor node class
bpy.utils.unregister_class(InvertColorsNode)
bpy.utils.unregister_class(InvertColorsOperator)
# Register the add-on when it is imported
register()
```
execute
method won't be used by the compositor.. If you want to create custom nodes for builtin NodeSystems, you need to use the CompositorNodeCustomGroup and build an internal nodetree with the functionality you want. $\endgroup$