# Example of creating and setting a Cycles material node with the Python API [duplicate]

I'm trying to set the properties of a Cycles material, which is linked to a Plane object, using the API.

So far this is what I've got:

1. Create a floor plane object:

bpy.ops.mesh.primitive_plane_add(radius=3, view_align=False, enter_editmode=False, location=(0, 0, 0))

my_floor = bpy.data.objects["Plane"]

2. Create the material for my floor, (I'm assuming it does not already exist):

my_floors_material_name = "Material"

#create the materials object
my_floors_material_object =    bpy.data.materials.new(my_floors_material_name)

#Enable 'Use nodes':
my_floors_material_object.use_nodes = True

3. Add a new node type from the list [types.ShaderNode][1]. I'd like to choose the equivalent of node_groups["Shader Nodetree"].nodes["Anisotropic BSDF"]:

#create the input node

#create the output node

#link the input and output nodes, on the node tree of my object

#this runs and returns

4. Assign the floor material to the floor object:

#assign the material object, to the plane object
my_floor.data.materials.append( my_floors_material_object )


Unfortunately it does not work? Here's the floor I want to create, (the shinny one below the statue)

Here's what I get with my current script:

Seems like it should an easy thing to do, but I'm confused? Here's the a link that I used to get started, Control Cycles material nodes and material properties in Python

Thanks a lot for any help!

• As last step you only have to assign the material to the object, see: blender.stackexchange.com/questions/23433/… – p2or Jun 21 '15 at 12:13
• Hey poor, thanks alot for the link :) I've added the last step as you advise, and I also found out how to create the materials object using the API from here, blender.stackexchange.com/questions/5668/… Unfortunately it still doesn't work ? – Ajay T Jun 21 '15 at 12:44
• What exactly is not working? Error messages? – p2or Jun 21 '15 at 12:49
• The code runs without any error messages. It just does not do what I expect/want it to do? Basically the material of the floor/plane object is unchanged from Diffuse BSDF, (the default), and not Ansiotropic BSDF ; which is what I want the script to do. When I run the script, in the the Surface panel of the material, the box for the Surface, is unchanged from Diffuse BSDF to Anisotropic BSDF ??? So I think that's the problem? – Ajay T Jun 21 '15 at 13:01
• Please check your output Node, it should looks like: node_output = nodes.new(type='ShaderNodeOutputMaterial'), creating shader code: gist.github.com/p2or/… – p2or Jun 21 '15 at 13:28