Anim: add ensure parameter to KeyframeStrip.channels(...) RNA function

Add `ensure` boolean parameter to the `ActionKeyframeStrip.channels()` RNA
function. Passing `ensure=True` will ensure the channelbag for the given
action slot handle exists. This makes it more straight-forward to create
F-Curves for a slot regardless of whether there already was a channelbag
for those F-Cuves:

```python
strip = action.layers[0].strips[0]
slot = action.slots[0]

# Old:
channelbag = strip.channels(slot.handle)
if not channelbag:
    channelbag = strip.channelbags.new(action_slot)
ob_loc_x = channelbag.fcurves.new('location', index=0)

# New:
channelbag = strip.channels(slot.handle, ensure=True)
ob_loc_x = channelbag.fcurves.new('location', index=0)
```

Pull Request: https://projects.blender.org/blender/blender/pulls/133678
This commit is contained in:
Sybren A. Stüvel
2025-01-31 15:16:10 +01:00
parent 7f5c803a8b
commit 815337a7da
4 changed files with 23 additions and 3 deletions

View File

@@ -395,6 +395,10 @@ class ChannelbagsTest(unittest.TestCase):
self.strip.channelbags.remove(channelbag)
self.assertEqual([], list(self.strip.channelbags))
def test_ensure_channelbag(self):
channelbag = self.strip.channels(self.slot.handle, ensure=True)
self.assertEqual([channelbag], list(self.strip.channelbags))
def test_create_remove_fcurves(self):
channelbag = self.strip.channelbags.new(self.slot)