# Can't set color for a material in blender/python 2.8

I am attempting to create a plane and set the color; the following code throws an error at this line:

bpy.data.materials['RSgreen'].diffuse_color=(0,0,0)


the error is: ValueError: bpy_struct: item.attr = val: sequences of dimension 0 should contain 4 items, not 3

which makes no sense to me; diffuse_color calls for 3 parameters in the documentation.

bpy.ops.mesh.primitive_plane_add(size=4,enter_editmode=False,location=(-2,-2,0.01))
bpy.context.active_object.name='Plane2'
bpy.ops.material.new()
bpy.data.materials[1].name='RSgreen'
bpy.data.materials['RSgreen'].diffuse_color=(0,0,0)
bpy.context.object.data.materials.append(bpy.data.materials['RSgreen'])


You saw the wrong version of document, 2.80 change a lot. Ones should always use new document page for 2.80 version:

Material(ID) - Blender 2.80 API

# diffuse_color

Diffuse color of the material

Type: float array of 4 items in [0, inf], default (0.0, 0.0, 0.0, 0.0)

• What do the parameters mean? R,G,B,? ?? – vndep Jul 12 at 23:53
• @vndep RGB and Alpha – Sazerac Jul 13 at 0:30
• I am trying to get a green color (RGB=0,113,57; hex=#007139). When I pass the array (0,113,57,1) to .diffuse_color I get a light blue color instead. Same result when I convert the 0-255 values to percentiles. Any suggestions as to how to get that green? Maybe diffusion_color isn't the right property? – vndep Jul 13 at 1:17
• @vndep The description say it is an float number, and you should always consider the color value is in 0 to 1 rather 0 to 255. Divide your color value by 255 to fix it – Hikariztw Jul 13 at 1:40
• Thanks! That solves it. – vndep Jul 13 at 9:17