1
$\begingroup$

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()
$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – sambler Nov 5 '18 at 8:38
  • $\begingroup$ @sambler Ah thanks for the link, I didn't know it's obsolete. $\endgroup$ – Hitokage Nov 6 '18 at 19:18
  • $\begingroup$ @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? $\endgroup$ – Hitokage Nov 6 '18 at 21:15
  • $\begingroup$ 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. $\endgroup$ – sambler Nov 7 '18 at 7:34
  • 1
    $\begingroup$ 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#. $\endgroup$ – Secrop Mar 28 at 5:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.