I would like to be able to apply and edit a material to objects I have create using python script. I am using the cycles render engine but can't find a way to get this to work.

I've tried a bunch of the answers already given in other threads but none of them seem to work.

I would like to: create and apply a new material for each object and adjust the colours using rgb, using nodes or otherwise.

Sorry if this is a stupid question, I'm very new to blender scripting!

  • 2
    $\begingroup$ Please add details as to what you have tried and at what point it doesn't work. $\endgroup$ – Ray Mairlot Aug 7 '15 at 10:59

The super-simple example is

import bpy

def mission1(obj):
    mat = bpy.data.materials.new("bacon")

    obj.data.materials[0] = mat

obj = bpy.context.active_object

If you need to actually create and rig nodes, update your question with a screenshot of nodes you have manually created and if I have time I'll cobble together some code to build a matching node tree using python.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.