2

I have a model about blender,there is a object (name's car_AudiA8) with multi-material,I want to copy a new object from the object ("car_AudiA8"),then change new object's color and old object's color is not affected,my method is :

obj = bpy.data.objects["car_AudiA8"]
mesh = obj.data
new_obj = bpy.data.objects.new("car_AudiA8", mesh)
bpy.context.scene.objects.link(new_obj)
bpy.ops.object.make_single_user(object = True, obdata = True, material = True,texture = True )
for slot in bpy.data.objects[new_obj.name].material_slots:
    if (slot.name.startswith("carpaint.Black")):
        bpy.data.materials[slot.name].diffuse_color = (1,0,0)

note: material("carpaint.Black") can control car's color .

1
  • 2
    This might be a better question for blender.stackexchange.com seeing as it concerns the blender api rather than a general programming problem Commented Jul 3, 2017 at 5:28

1 Answer 1

2

It looks like you're modifying the existing "carpaint.Black" material, which would affect all objects using that material. Instead, try assigning a new material to that slot

for slot in bpy.data.objects[new_obj.name].material_slots:
    if (slot.name.startswith("carpaint.Black")):
        new_mat = bpy.data.materials.new(name="carpaint.NewRed")
        new_mat.diffuse_color = (1,0,0)
        slot.material = new_mat

I'm not sure if this will work as is, but you get the idea. You might be better off copying the black material instead of just creating a new material from scratch.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you for the answer, I use " bpy.ops.object.make_single_user(object = True, obdata = True, material = True,texture = True )",it can separate new object's material and old object's material ,and new material's name is different from old material's name. and I don't need create new material ,please help me.
diffuse_color should have 4 elements in the tuple, RGB colors and Alpha intensity: (1, 0, 0, 1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.