Hello I want to change the material of some objects, since it is not applied the material, I want you to apply via code in python, is a group of three materials that is just an object, I want wif the cube gets a material a sphere with another material different from the cube, and a cone with another material different from the sphere and cube.

  • 3
    $\begingroup$ creating and assigning materials is covered here If you are using cycles then adding nodes to a material is also covered here $\endgroup$ – sambler Jan 18 '16 at 9:03
  • $\begingroup$ This question could be clearer. Your other question was about doing Booleans and I'd like to know if this question is a continuation of that. Do you mean you want to preserve the unique materials after doing a Boolean? so the resulting object (after boolean) has several materials given by the surfaces of the objects involved in the booleans? $\endgroup$ – zeffii Jan 18 '16 at 9:52
  • $\begingroup$ do you mean this kind of material assignment? : i.stack.imgur.com/V0iBe.png $\endgroup$ – zeffii Jan 18 '16 at 10:00

You need a reference to the material and the object.

import bpy

# alias as D because we'll use it alot.
D = bpy.data

red_material = D.materials["Red_Material"]
cube = D.objects['Cube']
cube.active_material = red_material
| improve this answer | |

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.