From bf8b64ae3067224d56c986fd2ca3a00ea8943624 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Tue, 14 Jun 2022 17:56:21 +0200 Subject: [PATCH] use query functions in TVPaint --- openpype/hosts/tvpaint/api/pipeline.py | 11 ++++++----- .../hosts/tvpaint/plugins/load/load_workfile.py | 13 +++++-------- .../tvpaint/plugins/publish/collect_instances.py | 11 +++++------ .../tvpaint/plugins/publish/collect_scene_render.py | 11 ++++------- .../tvpaint/plugins/publish/collect_workfile.py | 11 +++++------ 5 files changed, 25 insertions(+), 32 deletions(-) diff --git a/openpype/hosts/tvpaint/api/pipeline.py b/openpype/hosts/tvpaint/api/pipeline.py index 60c61a8cbfe..0118c0104bb 100644 --- a/openpype/hosts/tvpaint/api/pipeline.py +++ b/openpype/hosts/tvpaint/api/pipeline.py @@ -8,6 +8,7 @@ import pyblish.api +from openpype.client import get_project, get_asset_by_name from openpype.hosts import tvpaint from openpype.api import get_current_project_settings from openpype.lib import register_event_callback @@ -442,14 +443,14 @@ def set_context_settings(asset_doc=None): Change fps, resolution and frame start/end. """ + + project_name = legacy_io.active_project() if asset_doc is None: + asset_name = legacy_io.Session["AVALON_ASSET"] # Use current session asset if not passed - asset_doc = legacy_io.find_one({ - "type": "asset", - "name": legacy_io.Session["AVALON_ASSET"] - }) + asset_doc = get_asset_by_name(project_name, asset_name) - project_doc = legacy_io.find_one({"type": "project"}) + project_doc = get_project(project_name) framerate = asset_doc["data"].get("fps") if framerate is None: diff --git a/openpype/hosts/tvpaint/plugins/load/load_workfile.py b/openpype/hosts/tvpaint/plugins/load/load_workfile.py index 0eab083c227..462f12abf06 100644 --- a/openpype/hosts/tvpaint/plugins/load/load_workfile.py +++ b/openpype/hosts/tvpaint/plugins/load/load_workfile.py @@ -1,5 +1,6 @@ import os +from openpype.client import get_project, get_asset_by_name from openpype.lib import ( StringTemplate, get_workfile_template_key_from_context, @@ -44,21 +45,17 @@ def load(self, context, name, namespace, options): # Save workfile. host_name = "tvpaint" + project_name = context.get("project") asset_name = context.get("asset") task_name = context.get("task") # Far cases when there is workfile without context if not asset_name: + project_name = legacy_io.active_project() asset_name = legacy_io.Session["AVALON_ASSET"] task_name = legacy_io.Session["AVALON_TASK"] - project_doc = legacy_io.find_one({ - "type": "project" - }) - asset_doc = legacy_io.find_one({ - "type": "asset", - "name": asset_name - }) - project_name = project_doc["name"] + project_doc = get_project(project_name) + asset_doc = get_asset_by_name(project_name, asset_name) template_key = get_workfile_template_key_from_context( asset_name, diff --git a/openpype/hosts/tvpaint/plugins/publish/collect_instances.py b/openpype/hosts/tvpaint/plugins/publish/collect_instances.py index 782907b65d5..9b6d5c48799 100644 --- a/openpype/hosts/tvpaint/plugins/publish/collect_instances.py +++ b/openpype/hosts/tvpaint/plugins/publish/collect_instances.py @@ -2,6 +2,7 @@ import copy import pyblish.api +from openpype.client import get_asset_by_name from openpype.lib import get_subset_name_with_asset_doc from openpype.pipeline import legacy_io @@ -92,17 +93,15 @@ def process(self, context): if family == "review": # Change subset name of review instance + # Project name from workfile context + project_name = context.data["workfile_context"]["project"] + # Collect asset doc to get asset id # - not sure if it's good idea to require asset id in # get_subset_name? asset_name = context.data["workfile_context"]["asset"] - asset_doc = legacy_io.find_one({ - "type": "asset", - "name": asset_name - }) + asset_doc = get_asset_by_name(project_name, asset_name) - # Project name from workfile context - project_name = context.data["workfile_context"]["project"] # Host name from environment variable host_name = context.data["hostName"] # Use empty variant value diff --git a/openpype/hosts/tvpaint/plugins/publish/collect_scene_render.py b/openpype/hosts/tvpaint/plugins/publish/collect_scene_render.py index 2b8dbdc5b43..20c5bb586aa 100644 --- a/openpype/hosts/tvpaint/plugins/publish/collect_scene_render.py +++ b/openpype/hosts/tvpaint/plugins/publish/collect_scene_render.py @@ -2,8 +2,8 @@ import copy import pyblish.api +from openpype.client import get_asset_by_name from openpype.lib import get_subset_name_with_asset_doc -from openpype.pipeline import legacy_io class CollectRenderScene(pyblish.api.ContextPlugin): @@ -56,14 +56,11 @@ def process(self, context): # - not sure if it's good idea to require asset id in # get_subset_name? workfile_context = context.data["workfile_context"] - asset_name = workfile_context["asset"] - asset_doc = legacy_io.find_one({ - "type": "asset", - "name": asset_name - }) - # Project name from workfile context project_name = context.data["workfile_context"]["project"] + asset_name = workfile_context["asset"] + asset_doc = get_asset_by_name(project_name, asset_name) + # Host name from environment variable host_name = context.data["hostName"] # Variant is using render pass name diff --git a/openpype/hosts/tvpaint/plugins/publish/collect_workfile.py b/openpype/hosts/tvpaint/plugins/publish/collect_workfile.py index 70d92f82e9c..88c5f4dbc71 100644 --- a/openpype/hosts/tvpaint/plugins/publish/collect_workfile.py +++ b/openpype/hosts/tvpaint/plugins/publish/collect_workfile.py @@ -2,6 +2,7 @@ import json import pyblish.api +from openpype.client import get_asset_by_name from openpype.lib import get_subset_name_with_asset_doc from openpype.pipeline import legacy_io @@ -22,19 +23,17 @@ def process(self, context): basename, ext = os.path.splitext(filename) instance = context.create_instance(name=basename) + # Project name from workfile context + project_name = context.data["workfile_context"]["project"] + # Get subset name of workfile instance # Collect asset doc to get asset id # - not sure if it's good idea to require asset id in # get_subset_name? family = "workfile" asset_name = context.data["workfile_context"]["asset"] - asset_doc = legacy_io.find_one({ - "type": "asset", - "name": asset_name - }) + asset_doc = get_asset_by_name(project_name, asset_name) - # Project name from workfile context - project_name = context.data["workfile_context"]["project"] # Host name from environment variable host_name = os.environ["AVALON_APP"] # Use empty variant value