From 28d0bef7065ce987cd960e19eabd614f22bf4ead Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Thu, 3 Apr 2025 10:18:15 +0200 Subject: [PATCH] Fix: Retain slot name when baking action Previously when an action was baked, the slot name was not retained. This causes problems when switching between actions because the slot will not automatically be assigned. This is now fixed by ensuring that the name of the last assigned slot is used to create the new slot. Pull Request: https://projects.blender.org/blender/blender/pulls/136814 --- scripts/modules/bpy_extras/anim_utils.py | 3 ++- tests/python/bl_animation_bake.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/modules/bpy_extras/anim_utils.py b/scripts/modules/bpy_extras/anim_utils.py index 0ed9b73db76..c6aa64df7ab 100644 --- a/scripts/modules/bpy_extras/anim_utils.py +++ b/scripts/modules/bpy_extras/anim_utils.py @@ -393,6 +393,7 @@ def bake_action_iter( # in case animation data hasn't been created atd = obj.animation_data_create() + old_slot_name = atd.last_slot_identifier[2:] is_new_action = action is None if is_new_action: action = bpy.data.actions.new("Action") @@ -406,7 +407,7 @@ def bake_action_iter( # A slot needs to be assigned. if not atd.action_slot: - slot = action.slots.new(obj.id_type, obj.name) + slot = action.slots.new(obj.id_type, old_slot_name or obj.name) atd.action_slot = slot # Baking the action only makes sense in Replace mode, so force it (#69105) diff --git a/tests/python/bl_animation_bake.py b/tests/python/bl_animation_bake.py index 737834c2d44..592cc1d85f1 100644 --- a/tests/python/bl_animation_bake.py +++ b/tests/python/bl_animation_bake.py @@ -76,6 +76,7 @@ class ObjectBakeTest(unittest.TestCase): self.assertNotEqual(action, self.obj.animation_data.action, "Expected baking to result in a new action") baked_action = self.obj.animation_data.action self.assertEqual(len(baked_action.slots), 1) + self.assertEqual(baked_action.slots[0].name_display, action.slots[0].name_display) channelbag = anim_utils.action_get_channelbag_for_slot(baked_action, self.obj.animation_data.action_slot) self.assertIsNotNone(channelbag) @@ -137,12 +138,14 @@ class ObjectBakeTest(unittest.TestCase): self.assertIsNotNone(self.obj.animation_data.action_slot) self.assertIsNotNone(obj2.animation_data.action_slot) - + self.assertNotEqual(self.obj.animation_data.action_slot, obj2.animation_data.action_slot) + original_slot = obj2.animation_data.action_slot anim_utils.bake_action_objects([(obj2, None)], frames=range(0, 10), bake_options=OBJECT_BAKE_OPTIONS) self.assertNotEqual(action, obj2.animation_data.action, "Expected baking to result in a new action") baked_action = obj2.animation_data.action self.assertEqual(len(baked_action.slots), 1) + self.assertEqual(original_slot.name_display, baked_action.slots[0].name_display) channelbag = anim_utils.action_get_channelbag_for_slot(baked_action, baked_action.slots[0]) for fcurve in channelbag.fcurves: