# Blender cycles, apply textures through a python script

I am trying to apply textures through a python script. I would like to use blender cycles renderer. I thought following these advices would be sufficient, but sadly Blender does not show the equivalent python commands when applying manually the procedure. How would you do this ? Or, is it possible to force blender to show the python commands ?

• – pink vertex Mar 7 '16 at 16:18

This script does not do any unwrapping. List of available nodes

import bpy

mat_name = "MyMaterial"
image_path = #...

mat = (bpy.data.materials.get(mat_name) or
bpy.data.materials.new(mat_name))

mat.use_nodes = True
nt = mat.node_tree
nodes = nt.nodes

# clear
while(nodes): nodes.remove(nodes[0])


• Couldn't you just do nodes.clear() instead of looping and removing them? Also, is there a way to auto-layout them after adding them? They're positioned on top of each other otherwise. – Ray Jun 9 '18 at 14:16