import spreadsheet
This commit is contained in:
@@ -210,6 +210,7 @@ class VSETB_OT_casting_move(Operator):
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class VSETB_OT_copy_casting(Operator):
|
||||
bl_idname = "vse_toolbox.copy_casting"
|
||||
bl_label = "Copy Casting"
|
||||
|
||||
+126
-3
@@ -6,15 +6,18 @@ from datetime import datetime
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from io import StringIO
|
||||
|
||||
import bpy
|
||||
from bpy.types import (Operator, Menu, OperatorFileListElement)
|
||||
from bpy.props import (EnumProperty, StringProperty, CollectionProperty)
|
||||
from bl_operators.presets import AddPresetBase
|
||||
|
||||
|
||||
from vse_toolbox.sequencer_utils import (get_strips, get_strip_sequence_name)
|
||||
from vse_toolbox.sequencer_utils import (get_strips, get_strip_sequence_name, get_channel_index)
|
||||
from vse_toolbox.bl_utils import (get_addon_prefs, get_scene_settings)
|
||||
from vse_toolbox.file_utils import (open_file, install_module, fuzzy_match)
|
||||
from vse_toolbox.file_utils import (open_file, install_module, fuzzy_match, norm_str)
|
||||
from vse_toolbox.constants import SPREADSHEET
|
||||
|
||||
|
||||
class VSETB_MT_export_spreadsheet_presets(Menu):
|
||||
@@ -146,10 +149,12 @@ class VSETB_OT_spreadsheet_from_clipboard(Operator):
|
||||
import_cells = project.spreadsheet_import.cells
|
||||
import_cells.clear()
|
||||
|
||||
SPREADSHEET.clear()
|
||||
|
||||
spreadsheet = context.window_manager.clipboard
|
||||
|
||||
cell_types = project.get_cell_types()
|
||||
rows = list(csv.reader(spreadsheet.splitlines(), delimiter='\t'))
|
||||
rows = list(csv.reader(StringIO(spreadsheet), delimiter='\t'))
|
||||
for cell_name in rows[0]:
|
||||
if not cell_name:
|
||||
continue
|
||||
@@ -161,7 +166,10 @@ class VSETB_OT_spreadsheet_from_clipboard(Operator):
|
||||
|
||||
project.spreadsheet_import.use_custom_cells = True
|
||||
|
||||
SPREADSHEET.extend(rows)
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class VSETB_OT_import_spreadsheet(Operator):
|
||||
bl_idname = "vse_toolbox.import_spreadsheet"
|
||||
@@ -252,6 +260,121 @@ class VSETB_OT_import_spreadsheet(Operator):
|
||||
col.separator()
|
||||
|
||||
def execute(self, context):
|
||||
scn = context.scene
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
spreadsheet = project.spreadsheet_import
|
||||
sequencer = scn.sequence_editor.sequences
|
||||
|
||||
# Import Edit
|
||||
nb_frames_cell = next((c for c in spreadsheet.cells if c.import_name=='Nb Frames'), None)
|
||||
|
||||
channel = get_channel_index('Shots')
|
||||
|
||||
header = SPREADSHEET[0]
|
||||
|
||||
cell_types = project.get_cell_types()
|
||||
cell_names = {k: spreadsheet.cells[k].import_name for k in header if k}
|
||||
|
||||
separator = spreadsheet.separator.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
frame_start = scn.frame_start
|
||||
for row in SPREADSHEET[1:]:
|
||||
cell_data = {cell_names[k]: v for k, v in zip(header, row) if k}
|
||||
#cell_data = {k: v for k, v in zip(header, row)}
|
||||
shot_name = cell_data['Shot']
|
||||
nb_frames = int(cell_data['Nb Frames'])
|
||||
|
||||
strip = next((s for s in sequencer if s.vsetb_strip_settings.source_name == shot_name), None)
|
||||
|
||||
print("shot_name", shot_name, strip)
|
||||
|
||||
if spreadsheet.update_edit and nb_frames_cell.enabled:
|
||||
print('Import Edit')
|
||||
|
||||
#print(frame_start, nb_frames, type(nb_frames))
|
||||
frame_end = frame_start + nb_frames
|
||||
|
||||
if strip:
|
||||
if frame_start != strip.frame_final_start or frame_end !=strip.frame_final_end:
|
||||
print(f'The strip {strip.name} is updated with new range')
|
||||
|
||||
strip.frame_final_start = frame_start
|
||||
strip.frame_final_end = frame_end
|
||||
else:
|
||||
strip = sequencer.new_effect(
|
||||
name=shot_name,
|
||||
type='COLOR',
|
||||
channel=channel,
|
||||
frame_start=frame_start,
|
||||
frame_end=frame_end,
|
||||
)
|
||||
|
||||
strip.blend_alpha = 0.0
|
||||
strip.select = False
|
||||
strip.vsetb_strip_settings.source_name = shot_name
|
||||
|
||||
frame_start += nb_frames
|
||||
|
||||
if not strip:
|
||||
self.report({"WARNING"}, f'No strip found with source name {shot_name}, update the edit')
|
||||
|
||||
strip_settings = strip.vsetb_strip_settings
|
||||
|
||||
if spreadsheet.import_casting:
|
||||
strip_settings.casting.clear()
|
||||
|
||||
for cell_name, cell_value in zip(header, row):
|
||||
if not cell_name:
|
||||
continue
|
||||
|
||||
cell = spreadsheet.cells[cell_name]
|
||||
if not cell.enabled:
|
||||
continue
|
||||
|
||||
cell_type = cell_types[cell.import_name]
|
||||
|
||||
if cell.import_name == 'Description' and spreadsheet.import_custom_data:
|
||||
strip_settings.description = cell_value
|
||||
|
||||
elif cell_type == 'METADATA' and spreadsheet.import_custom_data:
|
||||
setattr(strip_settings.metadata, cell.import_name, cell_value)
|
||||
|
||||
if cell_type == 'ASSET_TYPE' and spreadsheet.import_casting:
|
||||
|
||||
print(cell_value)
|
||||
asset_names = cell_value.split('\n')
|
||||
|
||||
# Clear the list of assets
|
||||
#for asset_casting in list(strip_settings.casting):
|
||||
# if asset_casting.asset.asset_type == cell_name:
|
||||
# strip_settings.casting.remove(asset_casting)
|
||||
for asset_name in asset_names:
|
||||
if not asset_name:
|
||||
continue
|
||||
|
||||
print(asset_name)
|
||||
|
||||
asset = next((a for a in project.assets if norm_str(a.tracker_name) == norm_str(asset_name)), None)
|
||||
if asset:
|
||||
item = strip_settings.casting.add()
|
||||
item.name = asset.name
|
||||
item.id = asset.id
|
||||
item['_name'] = asset.label
|
||||
|
||||
strip_settings.casting.update()
|
||||
else:
|
||||
self.report({'WARNING'}, f'Asset {asset_name} not found in Project')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user