I have written a script in python in order to create a compositor node tree. It includes Group inside Group.
Here is an extraction of the first script
import bpy
-------------
INITIAL SETUP
switch on nodes and get reference
bpy.context.scene.use_nodes = True
nodetree = bpy.context.scene.node_tree
clear default nodes
for node in nodetree.nodes:
nodetree.nodes.remove(node)
-------------
Hub Group
adding nodegroup, node 2
node2 = nodetree.nodes.new("CompositorNodeGroup")
node2.location = (0, 0)
subtree description
node2.node_tree = bpy.data.node_groups.new(type="CompositorNodeTree", name="Hub")
node2_nodetree = node2.node_tree # shortcut; akin to nodetree
create input
node2_in = node2_nodetree.nodes.new("NodeGroupInput")
node2_in.location = (0, 0)
node2_nodetree.inputs.new("NodeSocketColor", "C1: Color")
-------------
H: Covering - NODE H
adding nodegroup, node H
nodeH = node2_nodetree.nodes.new("CompositorNodeGroup")
nodeH.location = (240, 260)
subtree description
nodeH.node_tree = bpy.data.node_groups.new(type="CompositorNodeTree", name="H: Covering")
nodeH_nodetree = nodeH.node_tree # shortcut; akin to nodetree
create input
nodeH_in = nodeH_nodetree.nodes.new("NodeGroupInput")
nodeH_in.location = (0, 0)
nodeH_nodetree.inputs.new("NodeSocketColor", "Cam-##_H1_Masks")
Note: you can execute this script to build what I am talking about
In an other script, I need to create and remove some links. Although I am able to call the node call "Hub Group" (level 0 of hierarchy) through these lines...
import bpy
S = bpy.data.scenes["Scene"]
node2 = S.node_tree.nodes["Group"] # This is "Hub"
... I can't figure out how to call the one inside Hub, call "node H"
I hope it's clear enough :) Thanks for your help!
solved script
import bpy
S = bpy.data.scenes["Scene"]
node2 = S.node_tree.nodes["Group"] # This is "Hub"
S.node_tree.nodes["Group"].node_tree.nodes["Group"]
S.node_tree.nodes["Group"].node_tree.nodes["Group"]. You can rename nodes withnode.name = "new_name"for convenience. Note there is also a label which is only for show and two nodes can share the same label contrary to the same name. – Gorgious Sep 02 '21 at 09:39