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
    shinny_floor_input_node = my_floors_material_nodes.new(type='ShaderNodeBsdfAnisotropic')
    #create the output node
    shinny_floor_output_node = my_floors_material_nodes.new(type='ShaderNodeOutputMaterial') 
    #link the input and output nodes, on the node tree of my object
        my_floors_material_object.node_tree.links.new(shinny_floor_input_node.outputs[0], shinny_floor_output_node.inputs[0])
    #this runs and returns 
    bpy.data.node_groups['Shader Nodetree']...NodeLink
  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)

Floor created using GUI

Here's what I get with my current script:

Floor created using API

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!

  • $\begingroup$ As last step you only have to assign the material to the object, see: blender.stackexchange.com/questions/23433/… $\endgroup$
    – p2or
    Jun 21, 2015 at 12:13
  • $\begingroup$ 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 ? $\endgroup$
    – Ajay T
    Jun 21, 2015 at 12:44
  • $\begingroup$ What exactly is not working? Error messages? $\endgroup$
    – p2or
    Jun 21, 2015 at 12:49
  • $\begingroup$ 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? $\endgroup$
    – Ajay T
    Jun 21, 2015 at 13:01
  • $\begingroup$ Please check your output Node, it should looks like: node_output = nodes.new(type='ShaderNodeOutputMaterial'), creating shader code: gist.github.com/p2or/… $\endgroup$
    – p2or
    Jun 21, 2015 at 13:28


Browse other questions tagged .