fix casting add and remove

pull/5/head
“christopheseux” 2023-05-11 11:29:26 +02:00
parent a46f64f034
commit f5275b88c8
2 changed files with 21 additions and 25 deletions

View File

@ -102,33 +102,31 @@ class VSETB_OT_casting_add(Operator):
def execute(self, context): def execute(self, context):
scn = context.scene scn = context.scene
item = get_strip_settings().active_casting settings = get_scene_settings()
label = item.asset.label if item.asset.label else 'Empty' project = settings.active_project
asset = project.assets[self.asset_name]
strips = get_strips('Shots', selected_only=True) strips = get_strips('Shots', selected_only=True)
for strip in strips: for strip in strips:
#active_strip = scn.sequence_editor.active_strip #active_strip = scn.sequence_editor.active_strip
settings = get_scene_settings()
strip_settings = strip.vsetb_strip_settings strip_settings = strip.vsetb_strip_settings
project = settings.active_project
if strip_settings.casting.get(self.asset_name): if strip_settings.casting.get(self.asset_name):
asset = project.assets[self.asset_name]
self.report({'WARNING'}, f"Asset {asset.label} already casted.") self.report({'WARNING'}, f"Asset {asset.label} already casted.")
return {"CANCELLED"} return {"CANCELLED"}
item = strip_settings.casting.add() item = strip_settings.casting.add()
asset = project.assets[self.asset_name]
item.name = asset.name item.name = asset.name
item.id = project.assets[self.asset_name].id item.id = asset.id
item['_name'] = asset.label item['_name'] = asset.label
strip_settings.casting.update() strip_settings.casting.update()
self.report({"INFO"}, f'Item {label} added in {len(strips)} shots') self.report({"INFO"}, f'Item {asset.label} added in {len(strips)} shots')
return {"FINISHED"} return {"FINISHED"}
@ -148,30 +146,28 @@ class VSETB_OT_casting_remove(Operator):
def invoke(self, context, event): def invoke(self, context, event):
scn = context.scene scn = context.scene
item = get_strip_settings().active_casting settings = get_strip_settings()
label = item.asset.label if item.asset.label else 'Empty' asset = settings.active_casting.asset
strips = get_strips('Shots', selected_only=True) strips = get_strips('Shots', selected_only=True)
strips_modified = 0 strips_modified = 0
for strip in strips: for strip in strips:
strip_settings = strip.vsetb_strip_settings strip_settings = strip.vsetb_strip_settings
idx = strip_settings.casting_index
try: for i, asset_casting in enumerate(list(strip_settings.casting)):
item = strip_settings.casting[idx] if asset_casting.asset == asset:
except IndexError: strip_settings.casting.remove(i)
continue
else:
strip_settings.casting.remove(idx)
if strip_settings.casting_index != 0: if strip_settings.casting_index != 0:
strip_settings.casting_index -= 1 strip_settings.casting_index -= 1
strips_modified += 1 strips_modified += 1
self.report({"INFO"}, f'Item {label} removed in {strips_modified} shots') continue
self.report({"INFO"}, f'Item {asset.label} removed in {strips_modified} shots')
return {"FINISHED"} return {"FINISHED"}

View File

@ -502,7 +502,7 @@ class VSETB_PGT_strip_settings(PropertyGroup):
@property @property
def active_casting(self): def active_casting(self):
try: try:
self.casting[self.casting_index] return self.casting[self.casting_index]
except IndexError: except IndexError:
return return