1
$\begingroup$

I have several objects sharing a material that is animating. I'm able to create copies of the material and assign them to each object, but the animation data is still the same for all materials (see .blend, attached). How can I create a copy of the animation data associated with the material as well?

import bpy

s_objs = bpy.context.selected_objects

for obj in s_objs:
    material_slots = obj.material_slots
    for mat_slot in material_slots:
        material = mat_slot.material
        new_material = material.copy()
        mat_slot.material = new_material

bpy.context.view_layer.update()

I also tried adding this, but animation_data is None

anim_data = material.animation_data.copy()
new_material.animation_data = anim_data

$\endgroup$

1 Answer 1

0
$\begingroup$

Copying the NodeTree's action seems to work:

import bpy

s_objs = bpy.context.selected_objects

for obj in s_objs:
    material_slots = obj.material_slots
    for mat_slot in material_slots:
        material = mat_slot.material
        new_material = material.copy()
        new_material.node_tree.animation_data.action = material.node_tree.animation_data.action.copy()
        mat_slot.material = new_material

bpy.context.view_layer.update()
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .