16
$\begingroup$

How do I add an already created node group into a node tree?

I have found that this works:

group = node_tree.nodes.new("ShaderNodeGroup")
group.node_tree = other_group.node_tree

But it creates a copy of other_group instead of just referencing it. So how would I go about just straight adding it to the node tree?

$\endgroup$

2 Answers 2

14
$\begingroup$

After adding the new node group node you can assign the node_group data type to the node_tree:

group = node_tree.nodes.new("ShaderNodeGroup")
group.node_tree = bpy.data.node_groups['OldNodeGroupName']
$\endgroup$
0
2
$\begingroup$

The only way I know is with operator with overwritten context. That means you will have to have a Node Editor window somewhere open:

context_copy = bpy.context.copy()
context_copy['area'] = next(area for area in bpy.context.screen.areas if area.type=='NODE_EDITOR')
bpy.ops.node.add_node(context_copy,
                      type="ShaderNodeGroup",
                      settings=[{"name":"node_tree", "value":"bpy.data.node_groups['GROUP']"}])
$\endgroup$
1
  • 3
    $\begingroup$ I can't believe there wouldn't be a way to do this otherwise, if no one else answers with something different then I will accept this. Thanks $\endgroup$ Commented Jan 29, 2015 at 17:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .