From 66994e81ca16db06911cb9ea8fcaf2e2896e7821 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Wed, 12 Jun 2024 16:53:43 +0300 Subject: [PATCH 1/5] Get the type name from the HDA definition --- .../client/ayon_houdini/plugins/load/load_hda.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server_addon/houdini/client/ayon_houdini/plugins/load/load_hda.py b/server_addon/houdini/client/ayon_houdini/plugins/load/load_hda.py index b04e211aa4..233ec91ced 100644 --- a/server_addon/houdini/client/ayon_houdini/plugins/load/load_hda.py +++ b/server_addon/houdini/client/ayon_houdini/plugins/load/load_hda.py @@ -28,14 +28,17 @@ def load(self, context, name=None, namespace=None, data=None): # Get the root node obj = hou.node("/obj") - # Create a unique name - counter = 1 namespace = namespace or context["folder"]["name"] - formatted = "{}_{}".format(namespace, name) if namespace else name - node_name = "{0}_{1:03d}".format(formatted, counter) + node_name = "{}_{}".format(namespace, name) if namespace else name hou.hda.installFile(file_path) - hda_node = obj.createNode(name, node_name) + + # Get the type name from the HDA definition. + hda_defs = hou.hda.definitionsInFile(file_path) + for hda_def in hda_defs: + type_name = hda_def.nodeTypeName() + + hda_node = obj.createNode(type_name, node_name) self[:] = [hda_node] From 92c000aabf9051bceb3764027c3afe299fb528dc Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Wed, 12 Jun 2024 16:54:31 +0300 Subject: [PATCH 2/5] create HDA with unique type name --- .../ayon_houdini/plugins/create/create_hda.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/server_addon/houdini/client/ayon_houdini/plugins/create/create_hda.py b/server_addon/houdini/client/ayon_houdini/plugins/create/create_hda.py index 6a1adce8cc..af7862b3ff 100644 --- a/server_addon/houdini/client/ayon_houdini/plugins/create/create_hda.py +++ b/server_addon/houdini/client/ayon_houdini/plugins/create/create_hda.py @@ -2,7 +2,11 @@ """Creator plugin for creating publishable Houdini Digital Assets.""" import ayon_api -from ayon_core.pipeline import CreatorError +from ayon_core.pipeline import ( + CreatorError, + get_current_project_name, + get_current_folder_path, +) from ayon_houdini.api import plugin import hou @@ -56,8 +60,18 @@ def create_instance_node( raise CreatorError( "cannot create hda from node {}".format(to_hda)) + # Pick a unique type name for HDA product per folder path per project. + type_name = ( + "{project_name}{folder_path}_{node_name}".format( + project_name=get_current_project_name(), + folder_path=get_current_folder_path().replace("/","_"), + node_name=node_name + ) + ) + hda_node = to_hda.createDigitalAsset( - name=node_name, + name=type_name, + description=node_name, hda_file_name="$HIP/{}.hda".format(node_name) ) hda_node.layoutChildren() From f464d190321d4c2289eb92c98c95eeb44eb0de53 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Wed, 12 Jun 2024 18:15:04 +0300 Subject: [PATCH 3/5] use the folder_path argument instead of get_current_folder_path() --- .../houdini/client/ayon_houdini/plugins/create/create_hda.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server_addon/houdini/client/ayon_houdini/plugins/create/create_hda.py b/server_addon/houdini/client/ayon_houdini/plugins/create/create_hda.py index af7862b3ff..694bc4f3c3 100644 --- a/server_addon/houdini/client/ayon_houdini/plugins/create/create_hda.py +++ b/server_addon/houdini/client/ayon_houdini/plugins/create/create_hda.py @@ -4,8 +4,7 @@ from ayon_core.pipeline import ( CreatorError, - get_current_project_name, - get_current_folder_path, + get_current_project_name ) from ayon_houdini.api import plugin import hou @@ -64,7 +63,7 @@ def create_instance_node( type_name = ( "{project_name}{folder_path}_{node_name}".format( project_name=get_current_project_name(), - folder_path=get_current_folder_path().replace("/","_"), + folder_path=folder_path.replace("/","_"), node_name=node_name ) ) From cc6c24c9829558679f41cb41427d5a938bccfa47 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Wed, 12 Jun 2024 18:29:38 +0300 Subject: [PATCH 4/5] use the first hda_def instead of using a for loop --- .../houdini/client/ayon_houdini/plugins/load/load_hda.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server_addon/houdini/client/ayon_houdini/plugins/load/load_hda.py b/server_addon/houdini/client/ayon_houdini/plugins/load/load_hda.py index 233ec91ced..fad9281c08 100644 --- a/server_addon/houdini/client/ayon_houdini/plugins/load/load_hda.py +++ b/server_addon/houdini/client/ayon_houdini/plugins/load/load_hda.py @@ -35,9 +35,10 @@ def load(self, context, name=None, namespace=None, data=None): # Get the type name from the HDA definition. hda_defs = hou.hda.definitionsInFile(file_path) - for hda_def in hda_defs: - type_name = hda_def.nodeTypeName() + if not hda_defs: + raise RuntimeError(f"No HDA definitions found in file: {file_path}") + type_name = hda_defs[0].nodeTypeName() hda_node = obj.createNode(type_name, node_name) self[:] = [hda_node] From f8e928f36c388b2335b421477fbea38fd2832ae5 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Thu, 13 Jun 2024 19:37:48 +0300 Subject: [PATCH 5/5] raise LoadError instead of RuntimeError --- .../houdini/client/ayon_houdini/plugins/load/load_hda.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server_addon/houdini/client/ayon_houdini/plugins/load/load_hda.py b/server_addon/houdini/client/ayon_houdini/plugins/load/load_hda.py index fad9281c08..5738ba7fab 100644 --- a/server_addon/houdini/client/ayon_houdini/plugins/load/load_hda.py +++ b/server_addon/houdini/client/ayon_houdini/plugins/load/load_hda.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import os from ayon_core.pipeline import get_representation_path +from ayon_core.pipeline.load import LoadError from ayon_houdini.api import ( pipeline, plugin @@ -36,7 +37,7 @@ def load(self, context, name=None, namespace=None, data=None): # Get the type name from the HDA definition. hda_defs = hou.hda.definitionsInFile(file_path) if not hda_defs: - raise RuntimeError(f"No HDA definitions found in file: {file_path}") + raise LoadError(f"No HDA definitions found in file: {file_path}") type_name = hda_defs[0].nodeTypeName() hda_node = obj.createNode(type_name, node_name)