diff --git a/openpype/hosts/houdini/api/lib.py b/openpype/hosts/houdini/api/lib.py index 96ca019f8f..dd8a5ba473 100644 --- a/openpype/hosts/houdini/api/lib.py +++ b/openpype/hosts/houdini/api/lib.py @@ -4,6 +4,7 @@ from contextlib import contextmanager import six +from openpype.client import get_asset_by_name from openpype.api import get_asset from openpype.pipeline import legacy_io @@ -74,16 +75,13 @@ def generate_ids(nodes, asset_id=None): """ if asset_id is None: + project_name = legacy_io.active_project() + asset_name = legacy_io.Session["AVALON_ASSET"] # Get the asset ID from the database for the asset of current context - asset_data = legacy_io.find_one( - { - "type": "asset", - "name": legacy_io.Session["AVALON_ASSET"] - }, - projection={"_id": True} - ) - assert asset_data, "No current asset found in Session" - asset_id = asset_data['_id'] + asset_doc = get_asset_by_name(project_name, asset_name, fields=["_id"]) + + assert asset_doc, "No current asset found in Session" + asset_id = asset_doc['_id'] node_ids = [] for node in nodes: @@ -430,26 +428,29 @@ def maintained_selection(): def reset_framerange(): """Set frame range to current asset""" + project_name = legacy_io.active_project() asset_name = legacy_io.Session["AVALON_ASSET"] - asset = legacy_io.find_one({"name": asset_name, "type": "asset"}) + # Get the asset ID from the database for the asset of current context + asset_doc = get_asset_by_name(project_name, asset_name) + asset_data = asset_doc["data"] - frame_start = asset["data"].get("frameStart") - frame_end = asset["data"].get("frameEnd") + frame_start = asset_data.get("frameStart") + frame_end = asset_data.get("frameEnd") # Backwards compatibility if frame_start is None or frame_end is None: - frame_start = asset["data"].get("edit_in") - frame_end = asset["data"].get("edit_out") + frame_start = asset_data.get("edit_in") + frame_end = asset_data.get("edit_out") if frame_start is None or frame_end is None: log.warning("No edit information found for %s" % asset_name) return - handles = asset["data"].get("handles") or 0 - handle_start = asset["data"].get("handleStart") + 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") + handle_end = asset_data.get("handleEnd") if handle_end is None: handle_end = handles diff --git a/openpype/hosts/houdini/api/usd.py b/openpype/hosts/houdini/api/usd.py index e9991e38ec..4f4a3d8e6f 100644 --- a/openpype/hosts/houdini/api/usd.py +++ b/openpype/hosts/houdini/api/usd.py @@ -6,6 +6,7 @@ import logging from Qt import QtWidgets, QtCore, QtGui from openpype import style +from openpype.client import get_asset_by_name from openpype.pipeline import legacy_io from openpype.tools.utils.assets_widget import SingleSelectAssetsWidget @@ -46,10 +47,8 @@ class SelectAssetDialog(QtWidgets.QWidget): select_id = None name = self._parm.eval() if name: - db_asset = legacy_io.find_one( - {"name": name, "type": "asset"}, - {"_id": True} - ) + project_name = legacy_io.active_project() + db_asset = get_asset_by_name(project_name, name, fields=["_id"]) if db_asset: select_id = db_asset["_id"] diff --git a/openpype/hosts/houdini/plugins/create/create_hda.py b/openpype/hosts/houdini/plugins/create/create_hda.py index 5fc78c7539..d15d5bcd29 100644 --- a/openpype/hosts/houdini/plugins/create/create_hda.py +++ b/openpype/hosts/houdini/plugins/create/create_hda.py @@ -1,6 +1,10 @@ # -*- coding: utf-8 -*- import hou +from openpye.client import ( + get_asset_by_name, + get_subsets, +) from openpype.pipeline import legacy_io from openpype.hosts.houdini.api import lib from openpype.hosts.houdini.api import plugin @@ -23,20 +27,16 @@ class CreateHDA(plugin.Creator): # type: (str) -> bool """Check if existing subset name versions already exists.""" # Get all subsets of the current asset - asset_id = legacy_io.find_one( - {"name": self.data["asset"], "type": "asset"}, - projection={"_id": True} - )['_id'] - subset_docs = legacy_io.find( - { - "type": "subset", - "parent": asset_id - }, - {"name": 1} + project_name = legacy_io.active_project() + asset_doc = get_asset_by_name( + project_name, self.data["asset"], fields=["_id"] + ) + subset_docs = get_subsets( + project_name, asset_ids=[asset_doc["_id"]], fields=["name"] ) - existing_subset_names = set(subset_docs.distinct("name")) existing_subset_names_low = { - _name.lower() for _name in existing_subset_names + subset_doc["name"].lower() + for subset_doc in subset_docs } return subset_name.lower() in existing_subset_names_low diff --git a/openpype/hosts/houdini/plugins/publish/collect_usd_bootstrap.py b/openpype/hosts/houdini/plugins/publish/collect_usd_bootstrap.py index 3f0d10e0ba..cf8d61cda3 100644 --- a/openpype/hosts/houdini/plugins/publish/collect_usd_bootstrap.py +++ b/openpype/hosts/houdini/plugins/publish/collect_usd_bootstrap.py @@ -1,5 +1,6 @@ import pyblish.api +from openyppe.client import get_subset_by_name, get_asset_by_name from openpype.pipeline import legacy_io import openpype.lib.usdlib as usdlib @@ -50,10 +51,8 @@ class CollectUsdBootstrap(pyblish.api.InstancePlugin): self.log.debug("Add bootstrap for: %s" % bootstrap) - asset = legacy_io.find_one({ - "name": instance.data["asset"], - "type": "asset" - }) + project_name = legacy_io.active_project() + asset = get_asset_by_name(project_name, instance.data["asset"]) assert asset, "Asset must exist: %s" % asset # Check which are not about to be created and don't exist yet @@ -70,7 +69,7 @@ class CollectUsdBootstrap(pyblish.api.InstancePlugin): self.log.debug("Checking required bootstrap: %s" % required) for subset in required: - if self._subset_exists(instance, subset, asset): + if self._subset_exists(project_name, instance, subset, asset): continue self.log.debug( @@ -93,7 +92,7 @@ class CollectUsdBootstrap(pyblish.api.InstancePlugin): for key in ["asset"]: new.data[key] = instance.data[key] - def _subset_exists(self, instance, subset, asset): + def _subset_exists(self, project_name, instance, subset, asset): """Return whether subset exists in current context or in database.""" # Allow it to be created during this publish session context = instance.context @@ -106,9 +105,8 @@ class CollectUsdBootstrap(pyblish.api.InstancePlugin): # Or, if they already exist in the database we can # skip them too. - return bool( - legacy_io.find_one( - {"name": subset, "type": "subset", "parent": asset["_id"]}, - {"_id": True} - ) - ) + if get_subset_by_name( + project_name, subset, asset["_id"], fields=["_id"] + ): + return True + return False diff --git a/openpype/hosts/houdini/plugins/publish/extract_usd_layered.py b/openpype/hosts/houdini/plugins/publish/extract_usd_layered.py index bfcd93c1cb..80919c023b 100644 --- a/openpype/hosts/houdini/plugins/publish/extract_usd_layered.py +++ b/openpype/hosts/houdini/plugins/publish/extract_usd_layered.py @@ -7,6 +7,12 @@ from collections import deque import pyblish.api import openpype.api +from openpype.client import ( + get_asset_by_name, + get_subset_by_name, + get_last_version_by_subset_id, + get_representation_by_name, +) from openpype.pipeline import ( get_representation_path, legacy_io, @@ -244,11 +250,14 @@ class ExtractUSDLayered(openpype.api.Extractor): # Set up the dependency for publish if they have new content # compared to previous publishes + project_name = legacy_io.active_project() for dependency in active_dependencies: dependency_fname = dependency.data["usdFilename"] filepath = os.path.join(staging_dir, dependency_fname) - similar = self._compare_with_latest_publish(dependency, filepath) + similar = self._compare_with_latest_publish( + project_name, dependency, filepath + ) if similar: # Deactivate this dependency self.log.debug( @@ -268,7 +277,7 @@ class ExtractUSDLayered(openpype.api.Extractor): instance.data["files"] = [] instance.data["files"].append(fname) - def _compare_with_latest_publish(self, dependency, new_file): + def _compare_with_latest_publish(self, project_name, dependency, new_file): import filecmp _, ext = os.path.splitext(new_file) @@ -276,35 +285,29 @@ class ExtractUSDLayered(openpype.api.Extractor): # Compare this dependency with the latest published version # to detect whether we should make this into a new publish # version. If not, skip it. - asset = legacy_io.find_one( - {"name": dependency.data["asset"], "type": "asset"} + asset = get_asset_by_name( + project_name, dependency.data["asset"], fields=["_id"] ) - subset = legacy_io.find_one( - { - "name": dependency.data["subset"], - "type": "subset", - "parent": asset["_id"], - } + subset = get_subset_by_name( + project_name, + dependency.data["subset"], + asset["_id"], + fields=["_id"] ) if not subset: # Subset doesn't exist yet. Definitely new file self.log.debug("No existing subset..") return False - version = legacy_io.find_one( - {"type": "version", "parent": subset["_id"], }, - sort=[("name", -1)] + version = get_last_version_by_subset_id( + project_name, subset["_id"], fields=["_id"] ) if not version: self.log.debug("No existing version..") return False - representation = legacy_io.find_one( - { - "name": ext.lstrip("."), - "type": "representation", - "parent": version["_id"], - } + representation = get_representation_by_name( + project_name, ext.lstrip("."), version["_id"] ) if not representation: self.log.debug("No existing representation..") diff --git a/openpype/hosts/houdini/plugins/publish/validate_usd_shade_model_exists.py b/openpype/hosts/houdini/plugins/publish/validate_usd_shade_model_exists.py index 44719ae488..b979b87d84 100644 --- a/openpype/hosts/houdini/plugins/publish/validate_usd_shade_model_exists.py +++ b/openpype/hosts/houdini/plugins/publish/validate_usd_shade_model_exists.py @@ -2,6 +2,7 @@ import re import pyblish.api +from openpype.client import get_subset_by_name import openpype.api from openpype.pipeline import legacy_io @@ -15,31 +16,23 @@ class ValidateUSDShadeModelExists(pyblish.api.InstancePlugin): label = "USD Shade model exists" def process(self, instance): - - asset = instance.data["asset"] + project_name = legacy_io.active_project() + asset_name = instance.data["asset"] subset = instance.data["subset"] # Assume shading variation starts after a dot separator shade_subset = subset.split(".", 1)[0] model_subset = re.sub("^usdShade", "usdModel", shade_subset) - asset_doc = legacy_io.find_one( - {"name": asset, "type": "asset"}, - {"_id": True} - ) + asset_doc = instance.data.get("assetEntity") if not asset_doc: - raise RuntimeError("Asset does not exist: %s" % asset) + raise RuntimeError("Asset document is not filled on instance.") - subset_doc = legacy_io.find_one( - { - "name": model_subset, - "type": "subset", - "parent": asset_doc["_id"], - }, - {"_id": True} + subset_doc = get_subset_by_name( + project_name, model_subset, asset_doc["_id"], fields=["_id"] ) if not subset_doc: raise RuntimeError( "USD Model subset not found: " - "%s (%s)" % (model_subset, asset) + "%s (%s)" % (model_subset, asset_name) )