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