Blender Kitsu: Add Episode Support to Edit Export Directory Import/Export #299

Open
Nick Alberelli wants to merge 2 commits from TinyNick/blender-studio-pipeline:feature/episode-support-for-editorial-exports into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
5 changed files with 38 additions and 17 deletions
Showing only changes of commit 60e79682e7 - Show all commits

View File

@ -1,5 +1,5 @@
import bpy
from .. import prefs
from .. import prefs, propsdata
import re
from pathlib import Path
@ -18,7 +18,7 @@ def edit_export_get_all(context: bpy.types.Context):
"""Find all renders in editorial export directory"""
addon_prefs = prefs.addon_prefs_get(context)
edit_export_path = Path(addon_prefs.edit_export_dir)
edit_export_path = propsdata.get_edit_export_dir()
files_list = [
f

View File

@ -3,7 +3,7 @@ from bpy.types import Sequence, Context
import os
from typing import Set, List
from pathlib import Path
from .. import cache, prefs, util
from .. import cache, prefs, util, propsdata
from ..types import Task, TaskStatus
from ..playblast.core import override_render_path, override_render_format
from . import opsdata
@ -149,7 +149,13 @@ class KITSU_OT_edit_export_set_version(bpy.types.Operator):
@classmethod
def poll(cls, context: bpy.types.Context) -> bool:
addon_prefs = prefs.addon_prefs_get(context)
return bool(addon_prefs.edit_export_dir != "")
if addon_prefs.edit_export_dir == "":
cls.poll_message_set("Edit Export Directory is not set, check add-on preferences")
return False
if not propsdata.get_edit_export_dir().exists():
cls.poll_message_set("Edit Export Directory does not exist")
return False
return True
def execute(self, context: bpy.types.Context) -> Set[str]:
kitsu_props = context.scene.kitsu

View File

@ -20,7 +20,7 @@
from typing import Any, List, Tuple
from pathlib import Path
from .. import prefs
from .. import prefs, propsdata
import bpy
from ..models import FileListModel
@ -43,7 +43,7 @@ def init_edit_export_file_model(
addon_prefs = prefs.addon_prefs_get(context)
kitsu_props = context.scene.kitsu
edit_export_dir = Path(addon_prefs.edit_export_dir)
edit_export_dir = propsdata.get_edit_export_dir()
# Is None if invalid.
if addon_prefs.edit_export_dir == "" or not edit_export_dir.exists():

View File

@ -28,7 +28,7 @@ from pathlib import Path
import bpy
from . import cache, bkglobals
from . import cache, bkglobals, propsdata
from .props import get_safely_string_prop
# TODO: restructure this to not access ops_playblast_data.
@ -608,7 +608,10 @@ class KITSU_addon_preferences(bpy.types.AddonPreferences):
def is_edit_export_root_valid(self) -> bool:
if self.edit_export_dir.strip() == "":
return False
if not Path(self.edit_export_dir).exists():
edit_export_path = Path(self.edit_export_dir)
if '<episode>' in edit_export_path.parts:
edit_export_path = propsdata.get_edit_export_dir()
if not edit_export_path.exists():
return False
return True

View File

@ -130,12 +130,7 @@ def get_playblast_dir(self: Any) -> str:
else:
playblast_dir = addon_prefs.shot_playblast_root_path
# Inject episode name if available (and if specified as <episode>)
if episode and '<episode>' in playblast_dir.parts:
i = playblast_dir.parts.index('<episode>')
playblast_dir = Path(*playblast_dir.parts[:i]).joinpath(
episode.name, *playblast_dir.parts[i + 1 :]
)
playblast_dir = set_episode_variable(playblast_dir)
if context_core.is_sequence_context():
playblast_dir = playblast_dir / sequence.name / 'sequence_previews'
@ -181,14 +176,18 @@ def get_playblast_file(self: Any) -> str:
return Path(self.playblast_dir).joinpath(file_name).as_posix()
def get_edit_export_dir() -> str:
addon_prefs = prefs.addon_prefs_get(bpy.context)
return set_episode_variable(Path(addon_prefs.edit_export_dir))
def get_edit_export_file(self: Any) -> str:
addon_prefs = prefs.addon_prefs_get(bpy.context)
if not bool(addon_prefs.edit_export_dir):
return ""
export_dir = get_edit_export_dir()
version = self.edit_export_version
file_pattern = addon_prefs.edit_export_file_pattern
file_name = file_pattern.replace('v###', version)
return Path(addon_prefs.edit_export_dir).joinpath(file_name).as_posix()
return export_dir.joinpath(file_name).as_posix()
_active_category_cache_init: bool = False
@ -227,3 +226,16 @@ def reset_all_kitsu_props(self: Any, context: bpy.types.Context) -> None:
cache.asset_active_reset(context)
cache.episode_active_reset(context)
cache.task_type_active_reset(context)
def set_episode_variable(base_path: Path) -> Path:
episode = cache.episode_active_get()
active_project = cache.project_active_get()
if not (
episode
and '<episode>' in base_path.parts
and active_project.production_type == bkglobals.KITSU_TV_PROJECT
):
return base_path
i = base_path.parts.index('<episode>')
return Path(*base_path.parts[:i]).joinpath(episode.name, *base_path.parts[i + 1 :])