How to connect new Mix Node(blender 3.4+) to other nodes via script

86 Views Asked by At

Blender 3.4 introduced new combined Mix node. Which combines float, vector and color operation together in one node. Previously for mixRGB node you could connect input socket [1] for color1 input.

mix_RGB_node = mat.node_tree.nodes.new(type='ShaderNodeMixRGB') #create a new mixRGB node
texture_node = mat.node_tree.nodes.new(type='ShaderNodeTexImage') #create a new Texture node
mat.node_tree.links.new(texture_node.outputs['Color'], mix_RGB_node.inputs[1]) #connect the texture nodes color output to the mix nodes color1 input

But doing this for new Mix node doesn't work.

Tried to do this, but this doesnt work. Same as for output socket[0] doesn't work either.

mix_RGB_node = mat.node_tree.nodes.new(type='ShaderNodeMix') #create a new mixRGB node
mix_RGB_node.data_type = 'RGBA'
texture_node = mat.node_tree.nodes.new(type='ShaderNodeTexImage') #create a new Texture node
mat.node_tree.links.new(texture_node.outputs['Color'], mix_RGB_node.inputs[1])
1

There are 1 best solutions below

0
Nazmul Islam On BEST ANSWER

for color, the new Mix nodes input sockets are [6][7], and for color output it's [2] other nodes are used by other modes(float,vector)

so the right code will be

mat.node_tree.links.new(texture_node.outputs['Color'], mix_RGB_node.inputs[6]) #this connects with inputA
mat.node_tree.links.new(principled_node.inputs['Base Color'],mix_RGB_node.outputs[2] ) #this connects mix output to the base color of Principle bsdf