Skip to content

Commit

Permalink
Support entity URIs in HDA path resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
BigRoy committed Aug 27, 2024
1 parent acf0d82 commit b26e55e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 25 deletions.
19 changes: 14 additions & 5 deletions client/ayon_houdini/api/hda_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ayon_core.style import load_stylesheet

from ayon_houdini.api import lib
from .usd import get_ayon_entity_uri_from_representation_context

from qtpy import QtCore, QtWidgets, QtGui
import hou
Expand Down Expand Up @@ -179,11 +180,19 @@ def set_representation(node, representation_id: str):

context = get_representation_context(project_name, repre_entity)
update_info(node, context)
path = get_representation_path_from_context(context)
# Load fails on UNC paths with backslashes and also
# fails to resolve @sourcename var with backslashed
# paths correctly. So we force forward slashes
path = path.replace("\\", "/")

if node.parm("use_ayon_entity_uri"):
use_ayon_entity_uri = node.evalParm("use_ayon_entity_uri")
else:
use_ayon_entity_uri = False
if use_ayon_entity_uri:
path = get_ayon_entity_uri_from_representation_context(context)
else:
path = get_representation_path_from_context(context)
# Load fails on UNC paths with backslashes and also
# fails to resolve @sourcename var with backslashed
# paths correctly. So we force forward slashes
path = path.replace("\\", "/")
with _unlocked_parm(file_parm):
file_parm.set(path)

Expand Down
22 changes: 2 additions & 20 deletions client/ayon_houdini/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import hou

import pyblish.api
import ayon_api
from ayon_core.pipeline import (
CreatorError,
Creator,
Expand All @@ -21,6 +20,7 @@
from ayon_core.lib import BoolDef

from .lib import imprint, read, lsattr, add_self_publish_button
from .usd import get_ayon_entity_uri_from_representation_context


SETTINGS_CATEGORY = "houdini"
Expand Down Expand Up @@ -321,25 +321,7 @@ class HoudiniLoader(load.LoaderPlugin):

def filepath_from_context(cls, context):
if cls.use_ayon_entity_uri:
project_name = context["project"]["name"]
representation_id = context["representation"]["id"]
response = ayon_api.post(
f"projects/{project_name}/uris",
entityType="representation",
ids=[representation_id])
if response.status_code != 200:
raise RuntimeError(
f"Unable to resolve AYON entity URI for '{project_name}' "
f"representation id '{representation_id}': {response.text}"
)
uris = response.data["uris"]
if len(uris) != 1:
raise RuntimeError(
f"Unable to resolve AYON entity URI for '{project_name}' "
f"representation id '{representation_id}' to single URI. "
f"Received data: {response.data}"
)
return uris[0]["uri"]
return get_ayon_entity_uri_from_representation_context(context)

return super(HoudiniLoader, cls).filepath_from_context(context)

Expand Down
40 changes: 40 additions & 0 deletions client/ayon_houdini/api/usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import List

import hou
import ayon_api
from pxr import Usd, Sdf, Tf, Vt, UsdRender

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -377,3 +378,42 @@ def get_schema_type_names(type_name: str) -> List[str]:
results.append(schema_type_name)

return results


def get_ayon_entity_uri_from_representation_context(context: dict) -> str:
"""Resolve AYON Entity URI from representation context.
Note:
The representation context is the `get_representation_context` dict
containing the `project`, `folder, `representation` and so forth.
It is not the representation entity `context` key.
Arguments:
context (dict): The representation context.
Raises:
RuntimeError: Unable to resolve to a single valid URI.
Returns:
str: The AYON entity URI.
"""
project_name = context["project"]["name"]
representation_id = context["representation"]["id"]
response = ayon_api.post(
f"projects/{project_name}/uris",
entityType="representation",
ids=[representation_id])
if response.status_code != 200:
raise RuntimeError(
f"Unable to resolve AYON entity URI for '{project_name}' "
f"representation id '{representation_id}': {response.text}"
)
uris = response.data["uris"]
if len(uris) != 1:
raise RuntimeError(
f"Unable to resolve AYON entity URI for '{project_name}' "
f"representation id '{representation_id}' to single URI. "
f"Received data: {response.data}"
)
return uris[0]["uri"]

0 comments on commit b26e55e

Please sign in to comment.