Blender Kitsu: Refactor Shot Builder #183

Merged
Nick Alberelli merged 55 commits from TinyNick/blender-studio-pipeline:feature/shot-builder-2 into main 2023-12-21 23:58:21 +01:00
2 changed files with 55 additions and 3 deletions
Showing only changes of commit cf1384c482 - Show all commits

View File

@ -0,0 +1,41 @@
import bpy
from pathlib import Path
from blender_kitsu.types import (
Sequence,
Shot,
TaskType,
)
from blender_kitsu import bkglobals, prefs
def get_task_type(task_type: TaskType) -> str:
for key, value in bkglobals.SHOT_TASK_MAPPING.items():
if value == task_type.name:
return key
def get_shot_task_name(shot: Shot, task_type: TaskType) -> str:
return f"{shot.name}{bkglobals.IN_FILE_DELIMITER}{get_task_type(task_type)}"
def get_file_dir(seq: Sequence, shot: Shot, task_type: TaskType) -> Path:
"""Returns Path to Directory for Current Shot, will ensure that
file path exists if it does not.
Args:
seq (Sequence): Sequence Class from blender_kitsu.types
shot (Shot): Shot Class from blender_kitsu.types
task_type TaskType Class from blender_kitsu.types
Returns:
Path: Returns Path for Shot Directory
"""
addon_prefs = prefs.addon_prefs_get(bpy.context)
project_root_dir = Path(addon_prefs.project_root_dir).resolve()
all_shots_dir = project_root_dir.joinpath('pro').joinpath('shots')
shot_dir = all_shots_dir.joinpath(seq.name).joinpath(shot.name)
if not shot_dir.exists():
shot_dir.mkdir(parents=True)
return shot_dir

View File

@ -1,7 +1,8 @@
import bpy import bpy
from pathlib import Path
from typing import List, Any, Tuple, Set, cast from typing import List, Any, Tuple, Set, cast
from blender_kitsu import prefs, cache from blender_kitsu import prefs, cache
from .core import get_shot_task_name, get_file_dir
active_project = None active_project = None
@ -114,13 +115,23 @@ class KITSU_OT_build_new_shot(bpy.types.Operator):
return task_type return task_type
def execute(self, context: bpy.types.Context): def execute(self, context: bpy.types.Context):
# Get Properties
global active_project global active_project
sequence = active_project.get_sequence(self.seq_id) seq = active_project.get_sequence(self.seq_id)
shot = active_project.get_shot(self.shot_id) shot = active_project.get_shot(self.shot_id)
task_type = self._get_task_type_for_shot(context, shot) task_type = self._get_task_type_for_shot(context, shot)
# Scene Naming
shot_task_name = get_shot_task_name(shot, task_type)
context.scene.name = shot_task_name
# File Path
# TODO Only run if saving file
dir = get_file_dir(seq, shot, task_type)
shot_file_path_str = dir.joinpath(shot_task_name).__str__()
print("Create shot with the following details") # TODO Remove print("Create shot with the following details") # TODO Remove
print(f"Seq Name: '{sequence.name}' Seq ID: '{self.seq_id}'") print(f"Seq Name: '{seq.name}' Seq ID: '{self.seq_id}'")
print(f"Shot Name: '{shot.name}' Shot ID: '{self.shot_id}'") print(f"Shot Name: '{shot.name}' Shot ID: '{self.shot_id}'")
print(f"Task Type Name: '{task_type.name}' Task Type ID: `{self.task_type}`") print(f"Task Type Name: '{task_type.name}' Task Type ID: `{self.task_type}`")
self.report({"INFO"}, f"Execution Complete") # TODO remove self.report({"INFO"}, f"Execution Complete") # TODO remove