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..)

object = bpy.data.objects['Cube']

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

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
| improve this answer | |
  • 1
    $\begingroup$ Slight issue here if material named Material doesn't exist, will throw a key error. $\endgroup$ – batFINGER Jan 2 '19 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.