I want to connect 2 nodes for all materials at once. Specifically the vertex color node with the mix vertex color node

I want to turn this:

enter image description here

Into this:

enter image description here

For every material.

Any help would be appreciated, not very familliar with python at all.


2 Answers 2


John's answer seems to be absolutely correct for how you presented your question. However, if you'd rephrase your question as:

How do I change each Vertex Color output going to a node labelled "Mix Vertex Color" to use Alpha output instead of Color?

Then the best answer I can come up with would be:

import bpy

for mat in bpy.data.materials:
    nodes = mat.node_tree.nodes if mat.node_tree else []
    vc_nodes = (n for n in nodes if n.type == 'VERTEX_COLOR')
    for vc, link in ((n, l) for n in vc_nodes for l in n.outputs['Color'].links):
        if link.to_node.label == 'Mix Vertex Color':
            mat.node_tree.links.new(vc.outputs[1], link.to_socket)
            print(f"Changed material {mat.name}")

This turns this:

into this:

That is, it iterates over all materials, and then makes sure to change each link from a node of type VERTEX_COLOR to a node with a label Mix Vertex Color, to go from the Alpha socket.

Alternative code

import bpy

check = lambda x: x.from_node.type=='VERTEX_COLOR' and x.to_node.label=='Mix Vertex Color'
trees = (m.node_tree for m in bpy.data.materials if m.node_tree)

for tree, l in [(t, l) for t in trees for l in t.links if check(l)]:
    tree.links.new(l.from_node.outputs[1], l.to_socket)

you can use this script:

import bpy

for eachMat in bpy.data.materials:
    if eachMat.node_tree is not None:
        if eachMat.node_tree.nodes.find("Vertex Color"):
            vertexColor = eachMat.node_tree.nodes["Vertex Color"]
             if eachMat.node_tree.nodes.find("Mix"):
                mix = eachMat.node_tree.nodes["Mix"]
                eachMat.node_tree.links.new(vertexColor.outputs[1], mix.inputs[2])
                print("changed:", eachMat.name)


Your nodes names must be "Mix" and "Vertex Color".

All changed materials will be printed out.


You must log in to answer this question.

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