Custom node : how to update values?

I’m trying to make some custom nodes with the template example and I don’t understand how to assign a value to the output socket or how to use the input one.


class MyCustomNode(bpy.types.Node):
    '''A custom node'''
    bl_idname = 'CustomNodeType'
    bl_label = 'Custom Node'

    
    def init(self, context):
        self.inputs.new('NodeSocketFloat', "inputA")
        self.inputs.new('NodeSocketVector', "inputB")

        self.outputs.new('NodeSocketColor', "outputA")
        self.outputs.new('NodeSocketFloat', "ouputB")

It creates well the sockets, but then, how to manipulate them and give a real value to the outputs of the node?

do u need to do it that way ?

I have another way to set I/O
but not like that !

but depends also what you want to do with it
can you elaborate a little !

happy bl

I actually found a way to do that but I have no idea if it’s the correct way for it.
The goal is just use the value of a property in another nodes.

I though that a socket has always a value attached to it and if I connect any node, it will use that value. But if I understood well, I found out that it is the opposite and the python nodes has to scan for the connected nodes and send them the values.

Am I right?

This seems to work :


    def update(self):
        
        try:
            output = self.outputs["FloatOutput"]
        except:
            output = None

        # I don't know why I can't use self.outputs["FloatOutput"] directly here, it tells me that "output" is not defined
        if output:
            for link in output.links:
                if link.is_valid:
                    link.to_socket.default_value = self.outputs["FloatOutput"].default_value

sorry might be possible but have not really work with this method
there might be some other thread using this method !

happy bl

What is your method? Maybe it is better :slight_smile:

try to run this script
with this you can set almost any of the mat or links for any nodes

addcubecolor1.blend (103 KB)

happy bl

Oh no no, I was talking about the Python nodes. I need new nodes that doesn’t exist and that is not possible to do with groups.

I suppose the solution I found is correct, but don’t find a lot of documentation about it.

like custom nodes !

don’t have much on that would also like to see more !

but I guess idea should be the same for I/O or links !
hope some one else can show some examples for custom nodes

note:
there is a template for custom nodes in text editor !

happy bl

I have something else to ask about custom nodes. Now I can send values to other nodes and read it from input socket but how to update it in any situation? There is a update(self) method that can be used to update values when nodes are connected. But it is not updated when properties or frames are changed. How to to that?

I know that atom did work on custom nodes with frames
try to search for custom nodes in forum !

happy bl