Anyone know how to read numpy arrays or even some variables from a socket? I can’t seem to figure out how. I’m trying to change and then read t_value variable from ImageSocket. What am I doing wrong?
ImageSocket class is the socket. ImageInputNode is supposed to write to this socket. ImageViewNode is supposed to read from the socket.
At some point I want to be able to move Numpy classes through the sockets. For now, simple variables would suffice.
class ImageSocket(bpy.types.NodeSocket): bl_idname = 'ImageSocket'
bl_label = 'Image Node Socket'
t_value = "img_sock_0"
# Optional function for drawing the socket input value
def draw(self, context, layout, node, text):
layout.label(text)
# Socket color
def draw_color(self, context, node):
return (0.0, 0.8, 0.0, 0.5)
class ImageEditNodeTree(bpy.types.NodeTree):
bl_idname = 'ImageTreeType'
bl_label = 'Image Edit Node Tree'
bl_icon = 'COLOR'
class ImageInputNode(bpy.types.Node):
bl_idname = 'ImageInputNodeType'
bl_label = 'Image Input Node'
available_objects = []
for im in bpy.data.images:
name = im.name
available_objects.append((name, name, name))
input_image = bpy.props.EnumProperty(name="", items=available_objects)
@classmethod
def poll(cls, tree):
return tree.bl_idname == 'ImageTreeType'
def draw_buttons(self, context, layout):
# layout.label("Node settings")
layout.prop(self, "input_image")
def init(self, context):
self.outputs.new('ImageSocket', "image out")
def update(self):
self.outputs['image out'].t_value = self.input_image
print('--'+ repr(self.outputs['image out']))
# print(self.outputs['image out'])
print(self.input_image)
# bpy.data.images['generated']
class ImageViewNode(bpy.types.Node):
bl_idname = 'ImageViewNodeType'
bl_label = 'Image View Node'
@classmethod
def poll(cls, tree):
return tree.bl_idname == 'ImageTreeType'
def draw_buttons(self, context, layout):
# print(self.img_name)
layout.label('foo')
def init(self, context):
print("node init")
self.inputs.new('ImageSocket', "image in")
self.img_name = "init"
def update(self):
self.img_name = 'foo'
if self.inputs['image in'].is_linked and self.inputs['image in'].links[0].is_valid:
iny = self.inputs['image in'].links[0].from_socket.t_value
else:
# iny = self.inputs['image in'].default_value
iny = "error"
print(iny)
import nodeitems_utils
from nodeitems_utils import NodeCategory, NodeItem
class MyNodeCategory(NodeCategory):
@classmethod
def poll(cls, context):
return context.space_data.tree_type == 'ImageTreeType'
node_categories = [
# identifier, label, items list
MyNodeCategory("IMAGEPNODES", "Image Processing Nodes", items=[
# our basic node
NodeItem("ImageInputNodeType"),
NodeItem("ImageViewNodeType"),
]),
]