Blender Kitsu: Refactor Shot Builder #183
@ -54,7 +54,7 @@ def get_shot_assets(
|
||||
print(f"'{key}': Succesfully Linked & Overriden")
|
||||
else:
|
||||
linked_collection = link_data_block(
|
||||
file_path=filepath, collection_name=key, data_block_type=data_type
|
||||
file_path=filepath, data_block_name=key, data_block_type=data_type
|
||||
)
|
||||
print(f"'{key}': Succesfully Linked")
|
||||
output_collection.children.link(linked_collection)
|
||||
|
@ -45,7 +45,7 @@ def set_render_engine(scene: bpy.types.Scene, engine='CYCLES'):
|
||||
scene.render.engine = engine
|
||||
|
||||
|
||||
def set_shot_scene(scene_name: str) -> bpy.types.Scene:
|
||||
def set_shot_scene(context: bpy.types.Context, scene_name: str) -> bpy.types.Scene:
|
||||
print(f"create scene with name {scene_name}")
|
||||
keep_scene = bpy.data.scenes.new(name=scene_name)
|
||||
for scene in bpy.data.scenes:
|
||||
@ -54,7 +54,7 @@ def set_shot_scene(scene_name: str) -> bpy.types.Scene:
|
||||
print(f"remove scene {scene.name}")
|
||||
bpy.data.scenes.remove(scene)
|
||||
|
||||
bpy.context.window.scene = keep_scene
|
||||
context.window.scene = keep_scene
|
||||
return keep_scene
|
||||
|
||||
|
||||
@ -76,14 +76,15 @@ def set_frame_range(shot: Shot, scene: bpy.types.Scene):
|
||||
scene.frame_end = start_3d + shot.nb_frames - 1
|
||||
|
||||
|
||||
def link_data_block(file_path: str, collection_name: str, data_block_type: str):
|
||||
def link_data_block(file_path: str, data_block_name: str, data_block_type: str):
|
||||
bpy.ops.wm.link(
|
||||
filepath=file_path,
|
||||
directory=file_path + "/" + data_block_type,
|
||||
filename=collection_name,
|
||||
filename=data_block_name,
|
||||
instance_collections=False,
|
||||
)
|
||||
return bpy.data.collections.get(collection_name)
|
||||
# TODO This doesn't return anything but collections
|
||||
return bpy.data.collections.get(data_block_name)
|
||||
|
||||
|
||||
def link_and_override_collection(
|
||||
|
@ -15,7 +15,7 @@ from .core import (
|
||||
|
||||
from .editorial import editorial_export_get_latest
|
||||
from .file_save import save_shot_builder_file
|
||||
from .template import open_template_for_task_type
|
||||
from .template import replace_workspace_with_template
|
||||
from .assets import get_shot_assets
|
||||
|
||||
active_project = None
|
||||
@ -141,12 +141,11 @@ class KITSU_OT_build_new_shot(bpy.types.Operator):
|
||||
task_short_name = task_type.get_short_name()
|
||||
|
||||
# Open Template File
|
||||
# TODO DEBUG WHY THIS CAUSES CRASHES
|
||||
# open_template_for_task_type(task_short_name)
|
||||
replace_workspace_with_template(context, task_short_name)
|
||||
|
||||
# Set Up Scene + Naming
|
||||
shot_task_name = shot.get_shot_task_name(task_type)
|
||||
scene = set_shot_scene(shot_task_name)
|
||||
scene = set_shot_scene(context, shot_task_name)
|
||||
set_resolution_and_fps(active_project, scene)
|
||||
set_frame_range(shot, scene)
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import bpy
|
||||
from pathlib import Path
|
||||
from .core import link_data_block
|
||||
|
||||
|
||||
# TODO add ability for custom templates
|
||||
@ -19,8 +20,47 @@ def get_template_for_task_type(task_short_name: str) -> Path:
|
||||
|
||||
|
||||
def open_template_for_task_type(task_short_name: str) -> bool:
|
||||
# TODO THIS DOESN'T WORK BECAUSE CHANGE THE OPEN FILE MESSES UP THE CONTEXT SOMEHOW
|
||||
file_path = get_template_for_task_type(task_short_name)
|
||||
if file_path.exists() and file_path is not None:
|
||||
bpy.ops.wm.open_mainfile(filepath=file_path.__str__())
|
||||
bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=file_path.__str__())
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def replace_workspace_with_template(context: bpy.types.Context, task_short_name: str):
|
||||
file_path = get_template_for_task_type(task_short_name).resolve().absolute()
|
||||
remove_prefix = "REMOVE-"
|
||||
if not file_path.exists():
|
||||
return
|
||||
|
||||
# Mark Existing Workspaces for Removal
|
||||
for workspace in bpy.data.workspaces:
|
||||
if workspace.name.startswith(remove_prefix):
|
||||
continue
|
||||
workspace.name = remove_prefix + workspace.name
|
||||
|
||||
file_path_str = file_path.__str__()
|
||||
with bpy.data.libraries.load(file_path_str) as (data_from, data_to):
|
||||
for workspace in data_from.workspaces:
|
||||
bpy.ops.wm.append(
|
||||
filepath=file_path_str,
|
||||
directory=file_path_str + "/" + 'WorkSpace',
|
||||
filename=str(workspace),
|
||||
)
|
||||
|
||||
for lib in bpy.data.libraries:
|
||||
if lib.filepath == file_path_str:
|
||||
bpy.data.libraries.remove(bpy.data.libraries.get(lib.name))
|
||||
break
|
||||
|
||||
workspaces_to_remove = []
|
||||
for workspace in bpy.data.workspaces:
|
||||
if workspace.name.startswith(remove_prefix):
|
||||
workspaces_to_remove.append(workspace)
|
||||
|
||||
# context.window.workspace = workspace
|
||||
for workspace in workspaces_to_remove:
|
||||
with context.temp_override(workspace=workspace):
|
||||
bpy.ops.workspace.delete()
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user