diff --git a/openpype/hosts/nuke/plugins/publish/collect_reads.py b/openpype/hosts/nuke/plugins/publish/collect_reads.py index 4d6944f523..b79d9646d5 100644 --- a/openpype/hosts/nuke/plugins/publish/collect_reads.py +++ b/openpype/hosts/nuke/plugins/publish/collect_reads.py @@ -3,6 +3,7 @@ import re import nuke import pyblish.api +from openpype.client import get_asset_by_name from openpype.pipeline import legacy_io @@ -16,12 +17,11 @@ class CollectNukeReads(pyblish.api.InstancePlugin): families = ["source"] def process(self, instance): - asset_data = legacy_io.find_one({ - "type": "asset", - "name": legacy_io.Session["AVALON_ASSET"] - }) + project_name = legacy_io.active_project() + asset_name = legacy_io.Session["AVALON_ASSET"] + asset_doc = get_asset_by_name(project_name, asset_name) - self.log.debug("asset_data: {}".format(asset_data["data"])) + self.log.debug("asset_doc: {}".format(asset_doc["data"])) self.log.debug("checking instance: {}".format(instance)) @@ -127,7 +127,7 @@ class CollectNukeReads(pyblish.api.InstancePlugin): "frameStart": first_frame, "frameEnd": last_frame, "colorspace": colorspace, - "handles": int(asset_data["data"].get("handles", 0)), + "handles": int(asset_doc["data"].get("handles", 0)), "step": 1, "fps": int(nuke.root()['fps'].value()) }) diff --git a/openpype/hosts/nuke/plugins/publish/precollect_writes.py b/openpype/hosts/nuke/plugins/publish/precollect_writes.py index 7e50679ed5..a7c07975e2 100644 --- a/openpype/hosts/nuke/plugins/publish/precollect_writes.py +++ b/openpype/hosts/nuke/plugins/publish/precollect_writes.py @@ -4,7 +4,10 @@ from pprint import pformat import nuke import pyblish.api -import openpype.api as pype +from openpype.client import ( + get_last_version_by_subset_name, + get_representations, +) from openpype.pipeline import ( legacy_io, get_representation_path, @@ -180,17 +183,26 @@ class CollectNukeWrites(pyblish.api.InstancePlugin): if not instance.data["review"]: instance.data["useSequenceForReview"] = False + project_name = legacy_io.active_project() + asset_name = instance.data["asset"] # * Add audio to instance if exists. # Find latest versions document - version_doc = pype.get_latest_version( - instance.data["asset"], "audioMain" + last_version_doc = get_last_version_by_subset_name( + project_name, "audioMain", asset_name=asset_name, fields=["_id"] ) + repre_doc = None - if version_doc: + if last_version_doc: # Try to find it's representation (Expected there is only one) - repre_doc = legacy_io.find_one( - {"type": "representation", "parent": version_doc["_id"]} - ) + repre_docs = list(get_representations( + project_name, version_ids=[last_version_doc["_id"]] + )) + if not repre_docs: + self.log.warning( + "Version document does not contain any representations" + ) + else: + repre_doc = repre_docs[0] # Add audio to instance if representation was found if repre_doc: