Set initial project settings.

# Conflicts:
#	pype/hooks/tvpaint/prelaunch.py
#	pype/hosts/tvpaint/__init__.py
This commit is contained in:
Toke Stuart Jepsen 2021-04-09 11:20:34 +01:00 committed by iLLiCiTiT
parent 47f3f27996
commit 0dd55198ee

View file

@ -2,13 +2,15 @@ import os
import logging
from avalon.tvpaint.communication_server import register_localization_file
from avalon.tvpaint import pipeline
from avalon.tvpaint import pipeline, lib
import pype.lib
import avalon.api
import avalon.io
import pyblish.api
from openpype.hosts import tvpaint
log = logging.getLogger("openpype.hosts.tvpaint")
log = logging.getLogger(__name__)
HOST_DIR = os.path.dirname(os.path.abspath(tvpaint.__file__))
PLUGINS_DIR = os.path.join(HOST_DIR, "plugins")
@ -34,6 +36,44 @@ def on_instance_toggle(instance, old_value, new_value):
pipeline._write_instances(current_instances)
def application_launch():
# Setup project settings if its the template that's launched.
if "PYPE_TVPAINT_LAUNCHED_TEMPLATE_FILE" in os.environ:
print("Setting up project...")
project_doc = avalon.io.find_one({"type": "project"})
project_data = project_doc["data"]
asset_data = pype.lib.get_asset()["data"]
framerate = asset_data.get("fps", project_data.get("fps", 25))
width_key = "resolutionWidth"
height_key = "resolutionHeight"
width = asset_data.get(width_key, project_data.get(width_key, 1920))
height = asset_data.get(height_key, project_data.get(height_key, 1080))
lib.execute_george("tv_resizepage {} {} 0".format(width, height))
lib.execute_george("tv_framerate {} \"timestretch\"".format(framerate))
frame_start = asset_data.get("frameStart")
frame_end = asset_data.get("frameEnd")
handles = asset_data.get("handles") or 0
handle_start = asset_data.get("handleStart")
if handle_start is None:
handle_start = handles
handle_end = asset_data.get("handleEnd")
if handle_end is None:
handle_end = handles
frame_start -= int(handle_start)
frame_end += int(handle_end)
lib.execute_george("tv_markin {} set".format(frame_start - 1))
lib.execute_george("tv_markout {} set".format(frame_end - 1))
def install():
log.info("OpenPype - Installing TVPaint integration")
localization_file = os.path.join(HOST_DIR, "resources", "avalon.loc")
@ -49,6 +89,8 @@ def install():
if on_instance_toggle not in registered_callbacks:
pyblish.api.register_callback("instanceToggled", on_instance_toggle)
avalon.api.on("application.launched", application_launch)
def uninstall():
log.info("OpenPype - Uninstalling TVPaint integration")