Merge pull request #5193 from ynput/bugfix/OP-6103_Resolve-post-start-functionality-fixes

Resolve: after launch automatization fixes
This commit is contained in:
Jakub Ježek 2023-06-28 13:20:49 +03:00 committed by GitHub
commit de10261ee2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 71 additions and 47 deletions

View file

@ -15,7 +15,6 @@ log = Logger.get_logger(__name__)
self = sys.modules[__name__]
self.project_manager = None
self.media_storage = None
self.current_project = None
# OpenPype sequential rename variables
self.rename_index = 0
@ -88,10 +87,7 @@ def get_media_storage():
def get_current_project():
"""Get current project object.
"""
if not self.current_project:
self.current_project = get_project_manager().GetCurrentProject()
return self.current_project
return get_project_manager().GetCurrentProject()
def get_current_timeline(new=False):

View file

@ -4,18 +4,15 @@ import os
from openpype.lib import Logger
from .lib import (
get_project_manager,
get_current_project,
set_project_manager_to_folder_name
get_current_project
)
log = Logger.get_logger(__name__)
exported_projet_ext = ".drp"
def file_extensions():
return [exported_projet_ext]
return [".drp"]
def has_unsaved_changes():
@ -30,13 +27,17 @@ def save_file(filepath):
project = get_current_project()
name = project.GetName()
if "Untitled Project" not in name:
log.info("Saving project: `{}` as '{}'".format(name, file))
pm.ExportProject(name, filepath)
else:
log.info("Creating new project...")
pm.CreateProject(fname)
pm.ExportProject(name, filepath)
response = False
if name == "Untitled Project":
response = pm.CreateProject(fname)
log.info("New project created: {}".format(response))
pm.SaveProject()
elif name != fname:
response = project.SetName(fname)
log.info("Project renamed: {}".format(response))
exported = pm.ExportProject(fname, filepath)
log.info("Project exported: {}".format(exported))
def open_file(filepath):
@ -57,10 +58,8 @@ def open_file(filepath):
file = os.path.basename(filepath)
fname, _ = os.path.splitext(file)
dname, _ = fname.split("_v")
try:
if not set_project_manager_to_folder_name(dname):
raise
# load project from input path
project = pm.LoadProject(fname)
log.info(f"Project {project.GetName()} opened...")
@ -79,14 +78,18 @@ def open_file(filepath):
def current_file():
pm = get_project_manager()
current_dir = os.getenv("AVALON_WORKDIR")
file_ext = file_extensions()[0]
workdir_path = os.getenv("AVALON_WORKDIR")
project = pm.GetCurrentProject()
name = project.GetName()
fname = name + exported_projet_ext
current_file = os.path.join(current_dir, fname)
if not current_file:
return None
return os.path.normpath(current_file)
project_name = project.GetName()
file_name = project_name + file_ext
# create current file path
current_file_path = os.path.join(workdir_path, file_name)
# return current file path if it exists
if os.path.exists(current_file_path):
return os.path.normpath(current_file_path)
def work_root(session):

View file

@ -1,17 +1,13 @@
import os
from openpype.lib import PreLaunchHook
import openpype.hosts.resolve
class ResolveLaunchLastWorkfile(PreLaunchHook):
class PreLaunchResolveLastWorkfile(PreLaunchHook):
"""Special hook to open last workfile for Resolve.
Checks 'start_last_workfile', if set to False, it will not open last
workfile. This property is set explicitly in Launcher.
"""
# Execute after workfile template copy
order = 10
app_groups = ["resolve"]
@ -30,16 +26,9 @@ class ResolveLaunchLastWorkfile(PreLaunchHook):
return
# Add path to launch environment for the startup script to pick up
self.log.info(f"Setting OPENPYPE_RESOLVE_OPEN_ON_LAUNCH to launch "
f"last workfile: {last_workfile}")
self.log.info(
"Setting OPENPYPE_RESOLVE_OPEN_ON_LAUNCH to launch "
f"last workfile: {last_workfile}"
)
key = "OPENPYPE_RESOLVE_OPEN_ON_LAUNCH"
self.launch_context.env[key] = last_workfile
# Set the openpype prelaunch startup script path for easy access
# in the LUA .scriptlib code
op_resolve_root = os.path.dirname(openpype.hosts.resolve.__file__)
script_path = os.path.join(op_resolve_root, "startup.py")
key = "OPENPYPE_RESOLVE_STARTUP_SCRIPT"
self.launch_context.env[key] = script_path
self.log.info("Setting OPENPYPE_RESOLVE_STARTUP_SCRIPT to: "
f"{script_path}")

View file

@ -5,7 +5,7 @@ from openpype.lib import PreLaunchHook
from openpype.hosts.resolve.utils import setup
class ResolvePrelaunch(PreLaunchHook):
class PreLaunchResolveSetup(PreLaunchHook):
"""
This hook will set up the Resolve scripting environment as described in
Resolve's documentation found with the installed application at

View file

@ -0,0 +1,24 @@
import os
from openpype.lib import PreLaunchHook
import openpype.hosts.resolve
class PreLaunchResolveStartup(PreLaunchHook):
"""Special hook to configure startup script.
"""
order = 11
app_groups = ["resolve"]
def execute(self):
# Set the openpype prelaunch startup script path for easy access
# in the LUA .scriptlib code
op_resolve_root = os.path.dirname(openpype.hosts.resolve.__file__)
script_path = os.path.join(op_resolve_root, "startup.py")
key = "OPENPYPE_RESOLVE_STARTUP_SCRIPT"
self.launch_context.env[key] = script_path
self.log.info(
f"Setting OPENPYPE_RESOLVE_STARTUP_SCRIPT to: {script_path}"
)

View file

@ -10,9 +10,11 @@ This code runs in a separate process to the main Resolve process.
"""
import os
from openpype.lib import Logger
import openpype.hosts.resolve.api
log = Logger.get_logger(__name__)
def ensure_installed_host():
"""Install resolve host with openpype and return the registered host.
@ -44,17 +46,22 @@ def open_file(path):
def main():
# Open last workfile
workfile_path = os.environ.get("OPENPYPE_RESOLVE_OPEN_ON_LAUNCH")
if workfile_path:
if workfile_path and os.path.exists(workfile_path):
log.info(f"Opening last workfile: {workfile_path}")
open_file(workfile_path)
else:
print("No last workfile set to open. Skipping..")
log.info("No last workfile set to open. Skipping..")
# Launch OpenPype menu
from openpype.settings import get_project_settings
from openpype.pipeline.context_tools import get_current_project_name
project_name = get_current_project_name()
log.info(f"Current project name in context: {project_name}")
settings = get_project_settings(project_name)
if settings.get("resolve", {}).get("launch_openpype_menu_on_start", True):
log.info("Launching OpenPype menu..")
launch_menu()

View file

@ -0,0 +1,5 @@
#! python3
from openpype.hosts.resolve.startup import main
if __name__ == "__main__":
main()