0
$\begingroup$

I want select a material, which already is define, of en object by using script.

How can I do that?

Example: This works but make everytime a new material. (Material.001, Material.002, ect..)

#******Material******
bpy.ops.object.select_all(action='DESELECT')
object = bpy.data.objects['Cube']

mat = bpy.data.materials.new("Material") 
print (mat)
me = object.data
me.materials.append(mat)
$\endgroup$
  • $\begingroup$ mat = bpy.data.materials.get("Material") or bpy.data.materials.new("Material") $\endgroup$ – batFINGER Jan 2 at 14:58
0
$\begingroup$

I have solved the problem by:

#***Set color***
D = bpy.data
Color_material = D.materials["Material"]
cube = D.objects['Cube']
cube.active_material = Color_material
$\endgroup$
  • 1
    $\begingroup$ Slight issue here if material named Material doesn't exist, will throw a key error. $\endgroup$ – batFINGER Jan 2 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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