In Blender/Python 2.8, I can't get my code to create the surface node I want (it creates a shader node along with a surface node that I don't want). The objective is to assign an image texture to an object as seen in three related posts (1, 2 and 3):
In Python I am attempting to do the same (code below), but the results aren't working out. First I'll show the output, then the code:
Here's the objectionable output:
And here's the node tree as created by my code; when I make the manual adjustments I note in the picture I get the final result that I want:
My flawed code is below. Before you criticize the obvious problem (that I am creating shaders), I have tried other approaches (replacing "Shader" with "Surface" and various other words) without success. I am also baffled as to why the "Principled BSDF" node appears out of nowhere.
Here's my code. Your suggestions would be highly appreciated. Thanks in advance!
matP_name='CCmat' matP = bpy.data.materials.get(matP_name) if matP is None: matP = bpy.data.materials.new(matP_name) matP.use_nodes=True nodes = matP.node_tree.nodes nodeID='ShaderNodeBsdfDiffuse' diffuse_BSDF = matP.node_tree.nodes.new(nodeID) path=TextureFolder+TextureFilenamePost imgTex = bpy.data.images.load(path) node_texture = nodes.new(type='ShaderNodeTexImage') node_texture.image = imgTex node_texture.location = 0,200 links = matP.node_tree.links link = links.new(node_texture.outputs, nodes.get('Diffuse BSDF').inputs) obj=bpy.data.objects['CubeCopy1'] obj.active_material=matP