Import Shots for mu

This commit is contained in:
ChristopheSeux
2024-03-26 17:54:03 +01:00
parent ac14fe5ba9
commit dae9d55494
5 changed files with 159 additions and 19 deletions
+97 -4
View File
@@ -2,21 +2,21 @@
from pathlib import Path
import bpy
from bpy.types import Operator
from bpy.types import Operator, UIList
from bpy.props import (CollectionProperty, BoolProperty, EnumProperty, StringProperty)
from vse_toolbox.constants import (EDITS, EDIT_SUFFIXES, MOVIES, MOVIE_SUFFIXES,
SOUNDS, SOUND_SUFFIXES)
from vse_toolbox.sequencer_utils import (clean_sequencer, import_edit, import_movie,
import_sound, get_strips)
import_sound, get_strips, get_channel_index)
from vse_toolbox.bl_utils import get_scene_settings
from vse_toolbox.file_utils import install_module
class VSETB_OT_auto_select_files(Operator):
bl_idname = "import.auto_select_files"
bl_idname = "vse_toolbox.auto_select_files"
bl_label = "Auto Select"
bl_description = "Auto Select Files"
bl_options = {"REGISTER", "UNDO"}
@@ -107,7 +107,7 @@ class VSETB_OT_import_files(Operator):
layout.use_property_decorate = False
col = layout.column(align=True)
col.operator('import.auto_select_files', text='Auto Select')
col.operator('vse_toolbox.auto_select_files', text='Auto Select')
row = layout.row(heading="Import Edit", align=True)
row.prop(self, 'import_edit')
@@ -190,9 +190,102 @@ class VSETB_OT_import_files(Operator):
return {"FINISHED"}
class VSETB_UL_import_task(UIList):
def draw_item(self, context, layout, data, item, icon, active_data,
active_propname, index):
layout.prop(item, 'import_enabled', text='')
layout.label(text=item.name)
class VSETB_OT_import_shots(Operator):
bl_idname = "vse_toolbox.import_shots"
bl_label = "Import Shots"
bl_description = "Import Shots for disk or tracker"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
return True
def execute(self, context):
scn = context.scene
settings = get_scene_settings()
project = settings.active_project
from gadget import Project
p = Project.from_env()
p.shots.fetch()
tasks = [t for t in project.task_types if t.import_enabled]
for i, task_type in enumerate(tasks):
channel_index = 9 + i
scn.sequence_editor.channels[channel_index].name = task_type.name
# Create Channels:
scn.sequence_editor.channels[9]
for strip in get_strips('Shots'):
for i, task_type in enumerate(tasks):
shot = p.shots[strip.name]
versions = shot.tasks[task_type.name].outputs[0].versions.fetch()
if versions:
print(versions[-1])
imported_strip = import_movie(versions[-1].path)
imported_strip.frame_start = strip.frame_start
if imported_strip.frame_final_duration != strip.frame_final_duration:
print(f'strip {strip.name} has different duration')
imported_strip.color_tag = 'COLOR_03'
imported_strip.frame_final_end = strip.frame_final_end
imported_strip.channel = get_channel_index(task_type.name)
print(get_channel_index(task_type.name), imported_strip.channel)
else:
print(f'No movie for {strip.name} of task {task_type.name}')
# for task_type in tasks:
# for strip in get_strips(task_type.name):
# strip.channel = get_channel_index(task_type.name)
return {'FINISHED'}
def draw(self, context):
settings = get_scene_settings()
project = settings.active_project
layout = self.layout
col = layout.column(align=False)
col.use_property_split = True
col.use_property_decorate = False
row = col.row(align=True)
row.prop(project, "import_source", text='Source', expand=True)
row = col.row(align=True)
row.prop(project, 'import_task', text='Import Tasks')
if project.import_task == 'SELECTED':
col.use_property_split = False
col.template_list("VSETB_UL_import_task", "import_task", project, "task_types", project, "task_type_index", rows=8)
def invoke(self, context, event):
scn = context.scene
settings = get_scene_settings()
project = settings.active_project
return context.window_manager.invoke_props_dialog(self)
classes = (
VSETB_UL_import_task,
VSETB_OT_auto_select_files,
VSETB_OT_import_files,
VSETB_OT_import_shots,
)
def register():
+32 -5
View File
@@ -1,12 +1,12 @@
from os.path import expandvars
import bpy
from bpy.types import Operator
from bpy.props import (BoolProperty, StringProperty)
from vse_toolbox.sequencer_utils import (get_strips, rename_strips, set_channels,
get_channel_index, new_text_strip, get_strip_at)
from vse_toolbox.bl_utils import get_scene_settings
get_channel_index, new_text_strip, get_strip_at, get_channel_name)
from vse_toolbox.bl_utils import get_scene_settings, get_strip_settings
class VSETB_OT_rename(Operator):
@@ -269,6 +269,32 @@ class VSETB_OT_next_shot(Operator):
return {"FINISHED"}
class VSETB_OT_open_shot_dir(Operator):
bl_idname = "vse_toolbox.open_shot_dir"
bl_label = "Open Shot Dir"
bl_description = "Open Shot Dir"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
strip = context.active_sequence_strip
return strip and get_channel_name(strip) == 'Shots'
def execute(self, context):
strip = context.active_sequence_strip
settings = get_scene_settings()
project = settings.active_project
strip_settings = get_strip_settings()
format_data = {**settings.format_data, **project.format_data, **strip_settings.format_data}
shot_dir_template = expandvars(project.shot_dir_template)
shot_dir_path = shot_dir_template.format(**format_data)
bpy.ops.wm.path_open(filepath=shot_dir_path)
return {"FINISHED"}
addon_keymaps = []
def register_keymaps():
@@ -304,7 +330,8 @@ classes = (
VSETB_OT_set_stamps,
VSETB_OT_show_waveform,
VSETB_OT_previous_shot,
VSETB_OT_next_shot
VSETB_OT_next_shot,
VSETB_OT_open_shot_dir
)
def register():