Fix #136947: Duplicate Action Slot doesn't duplicate animation data

The "new/duplicate" button in the Action Slot selector did not actually
duplicate, and always acted as a "new" button.

This introduces the RNA function `ActionSlot.duplicate()`, which takes
care of duplicating all the animation data associated with the slot as
well. The semantics of this function should remain valid in the
future, when Actions support multiple layers & strips. Note that this
new function does not assign the slot, it just duplicates it and its
data. The assignment of this duplicated slot is done in Python,
through the already-existing API for this.

Pull Request: https://projects.blender.org/blender/blender/pulls/137087
This commit is contained in:
Sybren A. Stüvel
2025-04-07 16:14:49 +02:00
parent a5ed5dc4bf
commit 9b1a34e83e
6 changed files with 167 additions and 6 deletions

View File

@@ -679,6 +679,10 @@ class ANIM_OT_slot_new_for_id(Operator):
Note that _which_ ID should get this slot must be set in the 'animated_id' context pointer, using:
>>> layout.context_pointer_set("animated_id", animated_id)
When the ID already has a slot assigned, the newly-created slot will be
named after it (ensuring uniqueness with a numerical suffix) and any
animation data of the assigned slot will be duplicated for the new slot.
"""
bl_idname = "anim.slot_new_for_id"
bl_label = "New Slot"
@@ -703,10 +707,14 @@ class ANIM_OT_slot_new_for_id(Operator):
def execute(self, context):
animated_id = context.animated_id
adt = animated_id.animation_data
action = animated_id.animation_data.action
slot = action.slots.new(animated_id.id_type, animated_id.name)
animated_id.animation_data.action_slot = slot
if adt.action_slot:
slot = adt.action_slot.duplicate()
else:
slot = adt.action.slots.new(animated_id.id_type, animated_id.name)
adt.action_slot = slot
return {'FINISHED'}