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):
scn = context.scene
item = get_strip_settings().active_casting
label = item.asset.label if item.asset.label else 'Empty'
settings = get_scene_settings()
project = settings.active_project
asset = project.assets[self.asset_name]
strips = get_strips('Shots', selected_only=True)
for strip in strips:
#active_strip = scn.sequence_editor.active_strip
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]
item.name = asset.name
item.id = project.assets[self.asset_name].id
item.id = asset.id
item['_name'] = asset.label
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"}
@ -148,30 +146,28 @@ class VSETB_OT_casting_remove(Operator):
def invoke(self, context, event):
scn = context.scene
item = get_strip_settings().active_casting
label = item.asset.label if item.asset.label else 'Empty'
settings = get_strip_settings()
asset = settings.active_casting.asset
strips = get_strips('Shots', selected_only=True)
strips_modified = 0
for strip in strips:
strip_settings = strip.vsetb_strip_settings
idx = strip_settings.casting_index
try:
item = strip_settings.casting[idx]
except IndexError:
continue
else:
for i, asset_casting in enumerate(list(strip_settings.casting)):
if asset_casting.asset == asset:
strip_settings.casting.remove(i)
strip_settings.casting.remove(idx)
if strip_settings.casting_index != 0:
strip_settings.casting_index -= 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"}

View File

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