Add Remove MoveUp-Down for Casting

This commit is contained in:
2023-03-17 20:03:38 +01:00
parent 4dc52b1268
commit 538c0bf60a
7 changed files with 332 additions and 57 deletions
+158 -2
View File
@@ -18,6 +18,7 @@ from bpy.types import (
)
from pathlib import Path
from vse_toolbox.constants import (
ASSETS,
EDITS,
MOVIES,
SOUNDS,
@@ -29,6 +30,7 @@ from vse_toolbox.sequencer_utils import (
clean_sequencer,
get_shot_sequence,
get_strips,
get_active_strip,
import_edit,
import_movie,
import_sound,
@@ -213,6 +215,49 @@ class VSETB_OT_import(Operator):
return {"FINISHED"}
class VSETB_OT_load_assets(Operator):
bl_idname = "vse_toolbox.load_assets"
bl_label = "Load Assets for current projects"
bl_description = "Load Assets"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
settings = get_settings()
if settings.active_project:
return True
def get_items(self, items=[]):
if not items:
return [('NONE', 'None', '', 0)]
item_sorted = [(e.name, e.name, '', i) for i, e in enumerate(sorted(items, key=lambda x:x.name))]
return item_sorted
def execute(self, context):
settings = get_settings()
prefs = get_addon_prefs()
tracker = prefs.tracker
ASSETS.clear()
settings.active_project.assets.clear()
project = settings.active_project
assets = tracker.get_assets(project['id'])
if not assets:
self.report({'ERROR'}, f'No Assets found for {project.name}.')
for asset_data in assets:
asset = project.assets.add()
asset.name = asset_data['name']
asset.id = asset_data['id']
asset.asset_type = asset_data['asset_type']
ASSETS.extend(self.get_items(items=project.assets))
self.report({'INFO'}, f'Assets for {project.name} successfully loaded')
return {"FINISHED"}
class VSETB_OT_load_projects(Operator):
bl_idname = "vse_toolbox.load_projects"
bl_label = "Load Projects"
@@ -240,7 +285,13 @@ class VSETB_OT_load_projects(Operator):
episode = project.episodes.add()
episode.name = episode_data['name']
episode.id = episode_data['id']
# for asset_data in tracker.get_assets(project_data):
# asset = project.assets.add()
# asset.name = asset_data['name']
# asset.id = asset_data['id']
# asset.asset_type = asset_data['asset_type']
return {'FINISHED'}
@@ -394,7 +445,7 @@ class VSETB_OT_render(Operator):
class VSETB_OT_set_scene(Operator):
bl_idname = "scene.set_scene"
bl_idname = "vse_toolbox.set_scene"
bl_label = "Set Scene"
bl_description = "Set Scene for Breakdown"
bl_options = {"REGISTER", "UNDO"}
@@ -420,10 +471,115 @@ class VSETB_OT_set_scene(Operator):
return {"FINISHED"}
class VSETB_OT_casting_add(Operator):
bl_idname = "vse_toolbox.casting_add"
bl_label = "Casting Add"
bl_description = "Add Asset to Castin"
bl_options = {"REGISTER", "UNDO"}
bl_property = "asset_name"
asset_name : EnumProperty(name='', items=lambda s, c: ASSETS)
@classmethod
def poll(cls, context):
active_strip = context.scene.sequence_editor.active_strip
if active_strip:
return True
def invoke(self, context, event):
context.window_manager.invoke_search_popup(self)
return {"FINISHED"}
def execute(self, context):
scn = context.scene
settings = get_settings()
active_strip = scn.sequence_editor.active_strip
project = settings.active_project
if active_strip.casting.get(self.asset_name):
self.report({'WARNING'}, f"Asset {self.asset_name} already casted.")
return {"CANCELLED"}
item = active_strip.casting.add()
item.name = self.asset_name
item.asset_type = project.assets[self.asset_name].asset_type
active_strip.casting.update()
return {"FINISHED"}
class VSETB_OT_casting_actions(Operator):
bl_idname = "vse_toolbox.casting_actions"
bl_label = "Casting Actions"
bl_description = "Actions to Add, Remove, Move casting items"
bl_options = {"REGISTER", "UNDO"}
action: EnumProperty(
items=(
('UP', "Up", ""),
('DOWN', "Down", ""),
('REMOVE', "Remove", ""),
)
)
asset_name : StringProperty()
@classmethod
def poll(cls, context):
active_strip = context.scene.sequence_editor.active_strip
if active_strip:
return True
def invoke(self, context, event):
scn = context.scene
active_strip = scn.sequence_editor.active_strip
idx = active_strip.casting_index
try:
item = active_strip.casting[idx]
except IndexError:
pass
else:
if self.action == 'DOWN' and idx < len(active_strip.casting) - 1:
item_next = active_strip.casting[idx+1].name
active_strip.casting.move(idx, idx+1)
active_strip.casting_index += 1
info = f"Item {item.name} moved to position {(item.name, active_strip.casting_index + 1)}"
self.report({'INFO'}, info)
elif self.action == 'UP' and idx >= 1:
item_prev = active_strip.casting[idx-1].name
active_strip.casting.move(idx, idx-1)
active_strip.casting_index -= 1
info = f"Item {item.name} moved to position {(item.name, active_strip.casting_index + 1)}"
self.report({'INFO'}, info)
elif self.action == 'REMOVE':
item = active_strip.casting[active_strip.casting_index]
active_strip.casting.remove(idx)
if active_strip.casting_index == 0:
active_strip.casting_index = 0
else:
active_strip.casting_index -= 1
info = f"Item {item.name} removed from casting"
self.report({'INFO'}, info)
return {"FINISHED"}
classes=(
VSETB_OT_auto_select_files,
VSETB_OT_casting_add,
VSETB_OT_casting_actions,
VSETB_OT_export_csv,
VSETB_OT_import,
VSETB_OT_load_assets,
VSETB_OT_load_projects,
VSETB_OT_new_episode,
VSETB_OT_reload_addon,