Created a custom node for image modification. Cannot retrieve the image data in any way from the socket, it's always None. Do you know whats the issue here?
The code:
import bpy
class ImageModifyNode(bpy.types.Node):
"""A custom node"""
bl_idname = "ImageModifyNode"
bl_label = "Modify image"
bl_description = "Modify image by changing colors"
def init(self, context):
self.inputs.new("NodeSocketImage", "Image")
self.inputs.new("NodeSocketColor", "Color 1")
self.inputs.new("NodeSocketColor", "Color 2")
self.outputs.new("NodeSocketImage", "Image")
# Copy function to initialize a copied node from an existing one.
def copy(self, node):
print(f"Copying from node {node}")
# Free function to clean up on removal.
def free(self):
print(f"Removing node {self}, Goodbye!")
def socket_value_update(self, context):
source_image = self.inputs.get("Image").default_value
print(f"socket_value_update {source_image=}")
def update(self):
source_image = self.inputs.get("Image").default_value
self.outputs.get("Image").default_value = source_image
print(f"update {source_image}")
class ImageModifyNodeAdd(bpy.types.Operator):
"""ImageModify node operator"""
bl_idname = "node.add_image_modify"
bl_label = "Add modify image node"
bl_description = "Modify image"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
bpy.ops.node.add_node(type=ImageModifyNode.bl_idname)
return {"FINISHED"}
def invoke(self, context, event):
bpy.ops.node.add_node(type=ImageModifyNode.bl_idname)
return {"FINISHED"}
-----------------------------------------------------------------------------
Node menu list
class NodeMenu(bpy.types.Menu):
"""AI node menu container"""
bl_idname = "NODE_MT_nodes"
bl_label = "Nodes"
def draw(self, context):
layout = self.layout
layout.operator(ImageModifyNodeAdd.bl_idname)
def add_node_button(self, context):
self.layout.separator()
self.layout.menu(NodeMenu.bl_idname, icon="PLUGIN")
classes = (ImageModifyNode, ImageModifyNodeAdd, NodeMenu)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.NODE_MT_add.append(add_node_button)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
bpy.types.NODE_MT_add.remove(add_node_button)
if name == "main":
register()
Expected:
Result of code:


you can't read the link/socket data in Python- but I was able to receive the image as seen in the example. Flattened image pixels will be printed. | 2.you will still be reading the original image data- what if we create new image in the environment after the modification so we are not referencing the same image?modified_image = bpy.data.images.new("ModifiedImage.png", width, height)– Tadas P42 Dec 21 '23 at 09:17bpy.data.images.new(). That way we are no longer reading original image – Tadas P42 Dec 21 '23 at 10:59