I'm trying to figure out how to change the linked node in a node group on a material via python
I'd like to do the equivalent of picking a new link via here -
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
Kinda similar to my other answer there.
It's not that trivial because some nodes change their displayed name depending on what they are representing. Group nodes are used to modify node groups but a node group is an actual standalone node tree.
So the green node you are seeing is not actually the node group it represents, but a virtual link to it. You can enter a new interface to modify the sub-node tree it is linked to, by using TAB or clicking on the icon on its top right corner, but they are two different entities.
That being said, you'll need to know your group node's unique identifying name, which is different from its displayed name, which is the sub-node-tree's name.
import bpy ao = bpy.context.active_object m = ao.active_material nodes = m.node_tree.nodes # Get material nodes gn = nodes.get("Group") # Get the group node (Name is case-sensitive) gn.node_tree = bpy.data.node_groups.get("NodeGroup") # Change the group node's node tree