From 95e5610ff91a06dc7b221ed5956f12ab66e853f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cchristopheseux=E2=80=9D?= <“seuxchristophe@hotmail.fr”> Date: Tue, 9 May 2023 18:25:41 +0200 Subject: [PATCH] casting on selection --- operators/casting.py | 71 ++++++++++++++++++++++++++------------------ ui/properties.py | 3 ++ 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/operators/casting.py b/operators/casting.py index 90df794..c35f6b6 100644 --- a/operators/casting.py +++ b/operators/casting.py @@ -101,26 +101,34 @@ class VSETB_OT_casting_add(Operator): def execute(self, context): scn = context.scene - active_strip = scn.sequence_editor.active_strip - settings = get_scene_settings() - strip_settings = get_strip_settings() + item = get_strip_settings().active_casting + label = item.asset.label if item.asset.label else 'Empty' - project = settings.active_project + strips = get_strips('Shots', selected_only=True) + for strip in strips: + #active_strip = scn.sequence_editor.active_strip - if strip_settings.casting.get(self.asset_name): + settings = get_scene_settings() + strip_settings = strip.vsetb_strip_settings + + project = settings.active_project + + if strip_settings.casting.get(self.asset_name): + asset = project.assets[self.asset_name] + self.report({'WARNING'}, f"Asset {asset.label} already casted.") + return {"CANCELLED"} + + item = strip_settings.casting.add() asset = project.assets[self.asset_name] - self.report({'WARNING'}, f"Asset {asset.label} already casted.") - return {"CANCELLED"} - item = strip_settings.casting.add() - asset = project.assets[self.asset_name] + item.name = asset.name + item.id = project.assets[self.asset_name].id + item['_name'] = asset.label - item.name = asset.name - item.id = project.assets[self.asset_name].id - item['_name'] = asset.label - - strip_settings.casting.update() + strip_settings.casting.update() + + self.report({"INFO"}, f'Item {label} added in {len(strips)} shots') return {"FINISHED"} @@ -140,25 +148,30 @@ class VSETB_OT_casting_remove(Operator): def invoke(self, context, event): scn = context.scene - strip_settings = get_strip_settings() - idx = strip_settings.casting_index + item = get_strip_settings().active_casting + label = item.asset.label if item.asset.label else 'Empty' - try: - item = strip_settings.casting[idx] - except IndexError: - pass - else: - item = strip_settings.casting[strip_settings.casting_index] - label = item.asset.label if item.asset.label else 'Empty' - info = f"Item {label} removed from casting" - strip_settings.casting.remove(idx) + strips = get_strips('Shots', selected_only=True) + strips_modified = 0 + for strip in strips: - if strip_settings.casting_index == 0: - strip_settings.casting_index = 0 + strip_settings = strip.vsetb_strip_settings + idx = strip_settings.casting_index + + try: + item = strip_settings.casting[idx] + except IndexError: + continue else: - strip_settings.casting_index -= 1 + + strip_settings.casting.remove(idx) + + if strip_settings.casting_index != 0: + strip_settings.casting_index -= 1 - self.report({'INFO'}, info) + strips_modified += 1 + + self.report({"INFO"}, f'Item {label} removed in {strips_modified} shots') return {"FINISHED"} diff --git a/ui/properties.py b/ui/properties.py index 7bf9e40..414a93a 100644 --- a/ui/properties.py +++ b/ui/properties.py @@ -499,6 +499,9 @@ class VSETB_PGT_strip_settings(PropertyGroup): metadata : PointerProperty(type=Metadata) description : StringProperty() + @property + def active_casting(self): + return self.casting[self.casting_index] classes = ( Asset,