I've been attempting to create a meterial, and add different textures to the properties using a script. I am testing with just a diffuse/color first, but am having trouble getting it to work.
I've tried various posts' answers, and even Blender 2.8 documentation and they all throw errors.
Blender code:
`bpy.ops.node.add_file(filepath="C:\Users\myName\Downloads\Textures\Downloaded\flooring5.jpg", filter_blender=False, filter_backup=False, filter_image=True, filter_movie=True, filter_python=False, filter_font=False, filter_sound=False, filter_text=False, filter_btx=False, filter_collada=False, filter_alembic=False, filter_folder=True, filter_blenlib=False, filemode=9, relative_path=True, show_multiview=False, use_multiview=False, display_type='DEFAULT', sort_method='FILE_SORT_ALPHA', name="Image")` My Error:
location: <unknown location>:-1 Error: File "C:\Users\nmaestre\Desktop\Projects\TextureShapes\TextureMesh.blend\Text", line 48 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape Current Working Code: (i found this from another post)
#Import python import bpy # Clear all nodes in a mat def clear_material( material ): if material.node_tree: material.node_tree.links.clear() material.node_tree.nodes.clear() # Create a node corresponding to a defined group def instanciate_group( nodes, group_name ): group = nodes.new( type = 'ShaderNodeGroup' ) group.node_tree = bpy.data.node_groups[group_name] #ref materials materials = bpy.data.materials #name material mat_name = 'Mat_Tile' # get ref to material material = materials.get( mat_name ) #if not our mat if not material: material = materials.new( mat_name ) # We clear it as we'll define it completely clear_material( material ) material.use_nodes = True nodes = material.node_tree.nodes links = material.node_tree.links output = nodes.new( type = 'ShaderNodeOutputMaterial' ) diffuse = nodes.new( type = 'ShaderNodeBsdfDiffuse' ) #input = nodes.new( type = 'ShaderNodeTexImage') #With names link = links.new( diffuse.outputs['BSDF'], output.inputs['Surface']) #Or with indices #link = links.new( diffuse.outputs[0], output.inputs[0] ) 