instance support to spreadsheet

pull/5/head
ChristopheSeux 2023-07-12 11:10:13 +02:00
parent 206aec490f
commit 18f830157f
1 changed files with 26 additions and 10 deletions

View File

@ -148,7 +148,7 @@ class VSETB_OT_spreadsheet_from_file(Operator):
rows = [r for r in rows if any(r)]
print('rows', rows)
#print('rows', rows)
cell_types = project.get_cell_types()
for cell_name in rows[0]:
@ -397,6 +397,9 @@ class VSETB_OT_import_spreadsheet(Operator):
if spreadsheet.import_casting:
strip_settings.casting.clear()
strip_settings.casting.update()
#print('Clear Casting of strip', strip)
for cell_name, cell_value in zip(header, row):
if not cell_name:
@ -429,17 +432,22 @@ class VSETB_OT_import_spreadsheet(Operator):
continue
#print(norm_str(asset_name), norm_str(project.assets[0].tracker_name))
norm_asset_name = norm_str(asset_name)
if spreadsheet.use_custom_name:
asset = next((a for a in project.assets if norm_str(a.get('metadata', {}).get(spreadsheet.custom_name)) == norm_str(asset_name)), None)
asset = next((a for a in project.assets if norm_str(a.get('metadata', {}).get(spreadsheet.custom_name)) == norm_asset_name), None)
else:
asset = next((a for a in project.assets if norm_str(a.tracker_name) == norm_str(asset_name)), None)
asset = next((a for a in project.assets if norm_str(a.tracker_name) == norm_asset_name), None)
if asset:
item = strip_settings.casting.add()
item.name = asset.name
item.id = asset.id
item['_name'] = asset.label
item = next((item for item in strip_settings.casting if item.asset == asset), None)
if item:
item.instance += 1
else:
item = strip_settings.casting.add()
item.name = asset.name
item.id = asset.id
item['_name'] = asset.label
strip_settings.casting.update()
else:
@ -546,7 +554,7 @@ class VSETB_OT_export_spreadsheet(Operator):
cells = spreadsheet.cells
rows.append([cell.name for cell in cells])
#print(rows)
print(rows)
#raise Exception('')
separator = spreadsheet.separator.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r')
@ -568,13 +576,14 @@ class VSETB_OT_export_spreadsheet(Operator):
if spreadsheet.use_custom_name and spreadsheet.use_custom_cells:
if asset.get('metadata', {}).get(spreadsheet.custom_name):
asset_castings.append(asset['metadata'][spreadsheet.custom_name])
asset_castings += [asset['metadata'][spreadsheet.custom_name]]*asset_casting.instance
else:
self.report({'ERROR'}, f'The asset {asset.tracker_name} has no data {spreadsheet.custom_name}')
else:
asset_castings.append(asset.tracker_name)
asset_castings += [asset.tracker_name]*asset_casting.instance
row += [separator.join(asset_castings)]
elif cell.field_name == 'EPISODE':
row += [settings.active_episode.name]
elif cell.field_name == 'SEQUENCE':
@ -614,12 +623,19 @@ class VSETB_OT_export_spreadsheet(Operator):
#2023_04_11_kitsu_boris_ep01_shots
export_path.parent.mkdir(parents=True, exist_ok=True)
if export_path.exists():
try:
print('Removing File', export_path)
export_path.unlink()
except Exception:
self.report({'ERROR'}, f'You need to close the file {export_path}')
if spreadsheet.format == 'csv':
print('Writing .csv file to', export_path)
with open(str(export_path), 'w', newline='\n', encoding='utf-8') as f:
writer = csv.writer(f, delimiter=spreadsheet.delimiter)
for row in rows:
#print(row)
writer.writerow(row)
elif spreadsheet.format == 'xlsx':