Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

General: Get current context document functions #3522

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion openpype/hosts/harmony/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
deregister_creator_plugin_path,
AVALON_CONTAINER_ID,
)
from openpype.pipeline.context_tools import get_current_project_asset
import openpype.hosts.harmony
import openpype.hosts.harmony.api as harmony

Expand Down Expand Up @@ -50,7 +51,9 @@ def get_asset_settings():
dict: Scene data.

"""
asset_data = lib.get_asset()["data"]

asset_doc = get_current_project_asset()
asset_data = asset_doc["data"]
fps = asset_data.get("fps")
frame_start = asset_data.get("frameStart")
frame_end = asset_data.get("frameEnd")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class ValidateSceneSettings(pyblish.api.InstancePlugin):

def process(self, instance):
"""Plugin entry point."""

# TODO 'get_asset_settings' could expect asset document as argument
# which is available on 'context.data["assetEntity"]'
# - the same approach can be used in 'ValidateSceneSettingsRepair'
expected_settings = harmony.get_asset_settings()
self.log.info("scene settings from DB:".format(expected_settings))

Expand Down
3 changes: 2 additions & 1 deletion openpype/hosts/hiero/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import openpype.api as openpype
from openpype.pipeline import LoaderPlugin, LegacyCreator
from openpype.pipeline.context_tools import get_current_project_asset
from . import lib

log = openpype.Logger().get_logger(__name__)
Expand Down Expand Up @@ -484,7 +485,7 @@ def _get_asset_data(self):

"""
asset_name = self.context["representation"]["context"]["asset"]
asset_doc = openpype.get_asset(asset_name)
asset_doc = get_current_project_asset(asset_name)
log.debug("__ asset_doc: {}".format(pformat(asset_doc)))
self.data["assetData"] = asset_doc["data"]

Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/houdini/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import six

from openpype.client import get_asset_by_name
from openpype.api import get_asset
from openpype.pipeline import legacy_io
from openpype.pipeline.context_tools import get_current_project_asset


import hou
Expand All @@ -16,7 +16,7 @@

def get_asset_fps():
"""Return current asset fps."""
return get_asset()["data"].get("fps")
return get_current_project_asset()["data"].get("fps")


def set_id(node, unique_id, overwrite=False):
Expand Down
14 changes: 8 additions & 6 deletions openpype/hosts/maya/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
get_last_versions,
get_representation_by_name
)
from openpype import lib
from openpype.api import get_anatomy_settings
from openpype.pipeline import (
legacy_io,
Expand All @@ -33,6 +32,7 @@
load_container,
registered_host,
)
from openpype.pipeline.context_tools import get_current_project_asset
from .commands import reset_frame_range


Expand Down Expand Up @@ -2174,7 +2174,7 @@ def reset_scene_resolution():
project_name = legacy_io.active_project()
project_doc = get_project(project_name)
project_data = project_doc["data"]
asset_data = lib.get_asset()["data"]
asset_data = get_current_project_asset()["data"]

# Set project resolution
width_key = "resolutionWidth"
Expand Down Expand Up @@ -2208,7 +2208,8 @@ def set_context_settings():
project_name = legacy_io.active_project()
project_doc = get_project(project_name)
project_data = project_doc["data"]
asset_data = lib.get_asset()["data"]
asset_doc = get_current_project_asset(fields=["data.fps"])
asset_data = asset_doc.get("data", {})

# Set project fps
fps = asset_data.get("fps", project_data.get("fps", 25))
Expand All @@ -2233,7 +2234,7 @@ def validate_fps():

"""

fps = lib.get_asset()["data"]["fps"]
fps = get_current_project_asset(fields=["data.fps"])["data"]["fps"]
# TODO(antirotor): This is hack as for framerates having multiple
# decimal places. FTrack is ceiling decimal values on
# fps to two decimal places but Maya 2019+ is reporting those fps
Expand Down Expand Up @@ -3051,8 +3052,9 @@ def update_content_on_context_change():
This will update scene content to match new asset on context change
"""
scene_sets = cmds.listSets(allSets=True)
new_asset = legacy_io.Session["AVALON_ASSET"]
new_data = lib.get_asset()["data"]
asset_doc = get_current_project_asset()
new_asset = asset_doc["name"]
new_data = asset_doc["data"]
for s in scene_sets:
try:
if cmds.getAttr("{}.id".format(s)) == "pyblish.avalon.instance":
Expand Down
6 changes: 3 additions & 3 deletions openpype/hosts/maya/plugins/create/create_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
from openpype.lib import requests_get
from openpype.api import (
get_system_settings,
get_project_settings,
get_asset)
get_project_settings)
from openpype.modules import ModulesManager
from openpype.pipeline import (
CreatorError,
legacy_io,
)
from openpype.pipeline.context_tools import get_current_project_asset


class CreateRender(plugin.Creator):
Expand Down Expand Up @@ -413,7 +413,7 @@ def _set_default_renderer_settings(self, renderer):
prefix,
type="string")

asset = get_asset()
asset = get_current_project_asset()

if renderer == "arnold":
# set format to exr
Expand Down
10 changes: 7 additions & 3 deletions openpype/hosts/maya/plugins/publish/validate_maya_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pyblish.api
import openpype.api
from openpype import lib
import openpype.hosts.maya.api.lib as mayalib
from openpype.pipeline.context_tools import get_current_project_asset
from math import ceil


Expand Down Expand Up @@ -41,7 +41,9 @@ def process(self, context):
# now flooring the value?
fps = float_round(context.data.get('fps'), 2, ceil)

asset_fps = lib.get_asset()["data"]["fps"]
# TODO repace query with using 'context.data["assetEntity"]'
asset_doc = get_current_project_asset()
asset_fps = asset_doc["data"]["fps"]

self.log.info('Units (linear): {0}'.format(linearunits))
self.log.info('Units (angular): {0}'.format(angularunits))
Expand Down Expand Up @@ -91,5 +93,7 @@ def repair(cls, context):
cls.log.debug(current_linear)

cls.log.info("Setting time unit to match project")
asset_fps = lib.get_asset()["data"]["fps"]
# TODO repace query with using 'context.data["assetEntity"]'
asset_doc = get_current_project_asset()
asset_fps = asset_doc["data"]["fps"]
mayalib.set_scene_fps(asset_fps)
4 changes: 2 additions & 2 deletions openpype/hosts/nuke/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
BuildWorkfile,
get_version_from_path,
get_workdir_data,
get_asset,
get_current_project_settings,
)
from openpype.tools.utils import host_tools
Expand All @@ -40,6 +39,7 @@
legacy_io,
Anatomy,
)
from openpype.pipeline.context_tools import get_current_project_asset

from . import gizmo_menu

Expand Down Expand Up @@ -1766,7 +1766,7 @@ def __init__(self, root_node=None, nodes=None, **kwargs):
kwargs.get("asset_name")
or legacy_io.Session["AVALON_ASSET"]
)
self._asset_entity = get_asset(self._asset)
self._asset_entity = get_current_project_asset(self._asset)
self._root_node = root_node or nuke.root()
self._nodes = self.get_nodes(nodes=nodes)

Expand Down
8 changes: 4 additions & 4 deletions openpype/hosts/nuke/plugins/publish/validate_script.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pyblish.api

from openpype.client import get_project, get_asset_by_id
from openpype import lib
from openpype.client import get_project, get_asset_by_id, get_asset_by_name
from openpype.pipeline import legacy_io


Expand All @@ -17,10 +16,11 @@ class ValidateScript(pyblish.api.InstancePlugin):

def process(self, instance):
ctx_data = instance.context.data
project_name = legacy_io.active_project()
asset_name = ctx_data["asset"]
asset = lib.get_asset(asset_name)
# TODO repace query with using 'instance.data["assetEntity"]'
asset = get_asset_by_name(project_name, asset_name)
asset_data = asset["data"]
project_name = legacy_io.active_project()

# These attributes will be checked
attributes = [
Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/resolve/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import qargparse
from Qt import QtWidgets, QtCore

import openpype.api as pype
from openpype.pipeline import (
LegacyCreator,
LoaderPlugin,
)
from openpype.pipeline.context_tools import get_current_project_asset
from openpype.hosts import resolve
from . import lib

Expand Down Expand Up @@ -375,7 +375,7 @@ def _get_asset_data(self):

"""
asset_name = self.context["representation"]["context"]["asset"]
self.data["assetData"] = pype.get_asset(asset_name)["data"]
self.data["assetData"] = get_current_project_asset(asset_name)["data"]

def load(self):
# create project bin for the media to be imported into
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import opentimelineio as otio
import pyblish.api
from openpype import lib as plib
from openpype.pipeline.context_tools import get_current_project_asset


class OTIO_View(pyblish.api.Action):
Expand Down Expand Up @@ -116,7 +117,7 @@ def process(self, instance):
if extension == ".edl":
# EDL has no frame rate embedded so needs explicit
# frame rate else 24 is asssumed.
kwargs["rate"] = plib.get_asset()["data"]["fps"]
kwargs["rate"] = get_current_project_asset()["data"]["fps"]

instance.data["otio_timeline"] = otio.adapters.read_from_file(
file_path, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import os
from copy import deepcopy

import opentimelineio as otio
import pyblish.api

from openpype import lib as plib
from copy import deepcopy
from openpype.pipeline.context_tools import get_current_project_asset


class CollectInstances(pyblish.api.InstancePlugin):
"""Collect instances from editorial's OTIO sequence"""
Expand Down Expand Up @@ -48,7 +52,7 @@ def process(self, instance):

# get timeline otio data
timeline = instance.data["otio_timeline"]
fps = plib.get_asset()["data"]["fps"]
fps = get_current_project_asset()["data"]["fps"]

tracks = timeline.each_child(
descended_from_type=otio.schema.Track
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pyblish.api

import openpype.api
from openpype import lib
from openpype.pipeline import PublishXmlValidationError
from openpype.pipeline.context_tools import get_current_project_asset


class ValidateFrameRange(pyblish.api.InstancePlugin):
Expand All @@ -27,7 +27,8 @@ def process(self, instance):
for pattern in self.skip_timelines_check):
self.log.info("Skipping for {} task".format(instance.data["task"]))

asset_data = lib.get_asset(instance.data["asset"])["data"]
# TODO repace query with using 'instance.data["assetEntity"]'
asset_data = get_current_project_asset(instance.data["asset"])["data"]
frame_start = asset_data["frameStart"]
frame_end = asset_data["frameEnd"]
handle_start = asset_data["handleStart"]
Expand Down
9 changes: 6 additions & 3 deletions openpype/hosts/unreal/plugins/load/load_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from unreal import MovieSceneSkeletalAnimationTrack
from unreal import MovieSceneSkeletalAnimationSection

from openpype.pipeline.context_tools import get_current_project_asset
from openpype.pipeline import (
get_representation_path,
AVALON_CONTAINER_ID
)
from openpype.hosts.unreal.api import plugin
from openpype.hosts.unreal.api import pipeline as unreal_pipeline
from openpype.api import get_asset


class AnimationFBXLoader(plugin.Loader):
Expand Down Expand Up @@ -53,6 +53,8 @@ def _process(self, asset_dir, asset_name, instance_name):
if not actor:
return None

asset_doc = get_current_project_asset(fields=["data.fps"])

task.set_editor_property('filename', self.fname)
task.set_editor_property('destination_path', asset_dir)
task.set_editor_property('destination_name', asset_name)
Expand Down Expand Up @@ -80,7 +82,7 @@ def _process(self, asset_dir, asset_name, instance_name):
task.options.anim_sequence_import_data.set_editor_property(
'use_default_sample_rate', False)
task.options.anim_sequence_import_data.set_editor_property(
'custom_sample_rate', get_asset()["data"].get("fps"))
'custom_sample_rate', asset_doc.get("data", {}).get("fps"))
task.options.anim_sequence_import_data.set_editor_property(
'import_custom_attribute', True)
task.options.anim_sequence_import_data.set_editor_property(
Expand Down Expand Up @@ -246,6 +248,7 @@ def load(self, context, name, namespace, options=None):
def update(self, container, representation):
name = container["asset_name"]
source_path = get_representation_path(representation)
asset_doc = get_current_project_asset(fields=["data.fps"])
destination_path = container["namespace"]

task = unreal.AssetImportTask()
Expand Down Expand Up @@ -279,7 +282,7 @@ def update(self, container, representation):
task.options.anim_sequence_import_data.set_editor_property(
'use_default_sample_rate', False)
task.options.anim_sequence_import_data.set_editor_property(
'custom_sample_rate', get_asset()["data"].get("fps"))
'custom_sample_rate', asset_doc.get("data", {}).get("fps"))
task.options.anim_sequence_import_data.set_editor_property(
'import_custom_attribute', True)
task.options.anim_sequence_import_data.set_editor_property(
Expand Down
5 changes: 3 additions & 2 deletions openpype/hosts/unreal/plugins/load/load_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
AVALON_CONTAINER_ID,
legacy_io,
)
from openpype.api import get_asset
from openpype.pipeline.context_tools import get_current_project_asset
from openpype.hosts.unreal.api import plugin
from openpype.hosts.unreal.api import pipeline as unreal_pipeline

Expand Down Expand Up @@ -225,6 +225,7 @@ def _import_animation(

anim_path = f"{asset_dir}/animations/{anim_file_name}"

asset_doc = get_current_project_asset()
# Import animation
task = unreal.AssetImportTask()
task.options = unreal.FbxImportUI()
Expand Down Expand Up @@ -259,7 +260,7 @@ def _import_animation(
task.options.anim_sequence_import_data.set_editor_property(
'use_default_sample_rate', False)
task.options.anim_sequence_import_data.set_editor_property(
'custom_sample_rate', get_asset()["data"].get("fps"))
'custom_sample_rate', asset_doc.get("data", {}).get("fps"))
task.options.anim_sequence_import_data.set_editor_property(
'import_custom_attribute', True)
task.options.anim_sequence_import_data.set_editor_property(
Expand Down
Loading