I am trying to create a series of materials nodes that are linked together. My script successfully creates a new material and connects a Mix node to the material output node. It also creates an Ambient Occlusion node, but fails to connect that AO node to the Mix node.

import bpy

mat = bpy.data.materials.get('test')
mat.use_nodes = True

#define where output of new node will link to
matout = mat.node_tree.nodes.get('Material Output')
#define new node type to link in
newmat = mat.node_tree.nodes.new('ShaderNodeMixShader')
#create new node with link
mat.node_tree.links.new(matout.inputs[0], newmat.outputs[0])

matout = mat.node_tree.nodes.get('ShaderNodeMixShader')
newmat = mat.node_tree.nodes.new('ShaderNodeAmbientOcclusion')
mat.node_tree.links.new(matout.inputs[0], newmat.outputs[0])

The console tells me that the matout = mat.node_tree.nodes.get('ShaderNodeMixShader') fails to find anything (AttributeError: 'NoneType' object has no attribute 'inputs').

Am I approaching this wrong?


1 Answer 1


Answering my own question ...

Once it is created, the node names are different. So you create a node using, e.g. ShaderNodeMixShader, but after that it is called 'Mix Shader' (i.e. as it appears in the node panel).

  • $\begingroup$ You could have also named the node while creating it: mat.node_tree.nodes.new( type="ShaderNodeMixShader", name="Mix Shader") docs.blender.org/api/current/… $\endgroup$
    – Ajay
    Commented Jun 16, 2022 at 20:26

You must log in to answer this question.

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