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?


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).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.