1
$\begingroup$

How can I create a new material and set it active material on the active object using python script.

$\endgroup$

1 Answer 1

2
$\begingroup$

You could do it like this:

obj = bpy.context.object  # Select the active object.
mat = bpy.data.materials.new(name='Material')  # Create a material.
# Settings for the material go here.
obj.data.materials.append(mat)  # Assign the new material.
$\endgroup$
1
  • 1
    $\begingroup$ bpy.ops.material.new(name='zz') now gives me 'keyword "name" unrecognized' in blender 2.9 $\endgroup$
    – james_t
    Commented Aug 2, 2021 at 19:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .