1

I am trying to make this simple node group that would simply connect the input to the output so it would simply repeat an image like below.

A complex repeater node use-case

What is the problem with my code? It's like nothing is coming out from the output.

import bpy

class Repeat (bpy.types.NodeCustomGroup):

    bl_name='Repeat'
    bl_label='Repeat'           

    def init(self, context):
        self.node_tree=bpy.data.node_groups.new(self.bl_name, 'CompositorNodeTree')
        if hasattr(self.node_tree, 'is_hidden'):
            self.node_tree.is_hidden=True

        self.node_tree.inputs.new("NodeSocketColor", "Image")
        self.node_tree.outputs.new("NodeSocketColor", "Image")
        self.node_tree.nodes.new('NodeGroupInput')
        self.node_tree.nodes.new('NodeGroupOutput') 

        #trying to connect input to output here, possible problem?
        self.node_tree.links.new(self.node_tree.nodes['Group Input'].outputs[0],self.node_tree.nodes['Group Output'].inputs[0])

    def free(self):
        bpy.data.node_groups.remove(self.node_tree, do_unlink=True)

from nodeitems_utils import NodeItem, register_node_categories, unregister_node_categories
from nodeitems_builtins import CompositorNodeCategory

def register():
    bpy.utils.register_class(Repeat)
    newcatlist = [CompositorNodeCategory("CP_GENERATE", "Testing", items=[NodeItem("Repeat"),]),]
    register_node_categories("GENERATE_NODES", newcatlist)

def unregister():
    unregister_node_categories("GENERATE_NODES")
    bpy.utils.unregister_class(Repeat)

try :
    unregister()
except:
    pass
register()
Hitokage
  • 207
  • 1
  • 7
  • 1
    The node stuff you are doing in register is from custom pynodes, use them only in their own custom node trees as they don't mix well with standard nodes. You want to create an operator that creates standard nodes in a group. The code in your init is close, but old - as in pre2.67, see this answer. – sambler Nov 05 '18 at 08:38
  • @sambler Ah thanks for the link, I didn't know it's obsolete. – Hitokage Nov 06 '18 at 19:18
  • @sambler OK seems like I managed to create a working node_tree but for some reason it's not working in the custom node but the same tree is working when assigned to a node group node. I however wanted to make the node customizable looking like standard nodes, not this ugly group :D. Any way how to do it? – Hitokage Nov 06 '18 at 21:15
  • As I mentioned, custom nodes do not interact with existing nodes, as one of the blender devs answered PyNodes do not make it possible to extend Blender Internal, Cycles or the compositor with new nodes. At this stage a group node is the option you have, you just have to accept having the node group list in your node until a developer offers a better solution. – sambler Nov 07 '18 at 07:34
  • @sambler I see, kinda weird but can't be helped I guess. Thank you for your help! :-) – Hitokage Nov 07 '18 at 07:38
  • @Hitokage I've checked the source code, and as I suspected the NodeCustomGroup is discard when the complete node tree is evaluated... For now, that class only works directly with Cycles nodetrees. – Secrop Nov 09 '18 at 15:46
  • @Secrop I see, can't be helped. Thanks anyway. – Hitokage Nov 09 '18 at 19:12
  • 2
    Just to update the information in this thread: 2.80 now gives the hability to create custom nodegroups for Compositor! One just needs to derive #CompositorNodeCustomGroup#, and work the same as using the former #NodeCustomGroup#. – Secrop Mar 28 '19 at 05:46
  • Amazing! Thank you so much @Secrop for this update and remembering this post!!! – Hitokage Mar 28 '19 at 19:26

0 Answers0