I'am beginner at python and blender. I' am trying to create simple addon for myself as part of learning process. I want to acheive that, if i run the script, mixrgb node is added to node tree and link to shader, and if i run script again another mixrgb node is added and linked to shader instead of previous one and previous one link to new one input. Here is the code
import bpy nodes = bpy.context.active_object.active_material.node_tree.nodes links = bpy.context.active_object.active_material.node_tree.links mix = nodes.new('ShaderNodeMixRGB') mix.location = (-300, -200) mix.label = "mix" for n in nodes : if n.label == "mix" : n.location.y -= 200 links.new(mix.outputs, nodes['Principled BSDF'].inputs)
Node is created and linked to shader, if i run the script again , new node is created and conected to shader ,previous one change its y location , and here i would like to link old node output to new node input.
links.new(mix.outputs , mix.inputs)
But it conects to itself. I dont want to make separate nodes like mixrgb2 mixrgb3, because i would like to be able to add infinite number of nodes , which are linked to previous.
If somebody can show me the correct way or creating that, iam stuck in that point for few days already. I was searching for solution here and every other forum, but no success, that 's why i decided to make a post.