diff --git a/server_addon/houdini/client/ayon_houdini/api/hda_utils.py b/server_addon/houdini/client/ayon_houdini/api/hda_utils.py index 0efe0434bc..be3869fbf3 100644 --- a/server_addon/houdini/client/ayon_houdini/api/hda_utils.py +++ b/server_addon/houdini/client/ayon_houdini/api/hda_utils.py @@ -542,3 +542,43 @@ def _select_folder_path(): folder_parm = node.parm("folder_path") folder_parm.set(selected_folder_path) folder_parm.pressButton() # allow any callbacks to trigger + + +def get_available_products(node): + """Return products menu items + It gets a list of available products of the specified product types + within the specified folder path with in the specified project. + Users can specify those in the HDA parameters. + Returns: + List[str]: Product options for Products menu. + """ + project_name = node.evalParm("project_name") + folder_path = node.evalParm("folder_path") + product_type = node.evalParm("product_type") + + folder_entity = ayon_api.get_folder_by_path(project_name, + folder_path, + fields={"id"}) + if not folder_entity: + return [] + + products = ayon_api.get_products( + project_name, + folder_ids=[folder_entity["id"]], + product_types=[product_type] + ) + + return([ + product["name"] for product in products + ]) + + +def refresh_version(node): + """Callback on product name change + + Refresh version parameter value by setting its value to + the latest version of the selected product. + """ + + versions = get_available_versions(node) + node.parm("version").set(str(versions[0])) diff --git a/server_addon/houdini/client/ayon_houdini/startup/otls/ayon_lop_import.hda/ayon_8_8Lop_1lop__import_8_81.0/DialogScript b/server_addon/houdini/client/ayon_houdini/startup/otls/ayon_lop_import.hda/ayon_8_8Lop_1lop__import_8_81.0/DialogScript index 924a8a91e9..7254da6913 100644 --- a/server_addon/houdini/client/ayon_houdini/startup/otls/ayon_lop_import.hda/ayon_8_8Lop_1lop__import_8_81.0/DialogScript +++ b/server_addon/houdini/client/ayon_houdini/startup/otls/ayon_lop_import.hda/ayon_8_8Lop_1lop__import_8_81.0/DialogScript @@ -47,12 +47,29 @@ parmtag { "script_callback" "hou.phm().on_representation_parms_changed(kwargs['node'])" } parmtag { "script_callback_language" "python" } } + parm { + name "product_type" + label "Product Type" + type string + default { "usd" } + } parm { name "product_name" label "Product" type string default { "usdAsset" } - parmtag { "script_callback" "hou.phm().on_representation_parms_changed(kwargs['node'])" } + menureplace { + [ "products = hou.phm().get_available_products(kwargs['node'])" ] + [ "" ] + [ "result = []" ] + [ "for product in products:" ] + [ " result.append(product)" ] + [ " result.append(product)" ] + [ " " ] + [ "return result" ] + language python + } + parmtag { "script_callback" "hou.phm().refresh_version(kwargs['node'])\nhou.phm().on_representation_parms_changed(kwargs['node'])" } parmtag { "script_callback_language" "python" } } parm { diff --git a/server_addon/houdini/client/ayon_houdini/startup/otls/ayon_lop_import.hda/ayon_8_8Lop_1lop__import_8_81.0/OnCreated b/server_addon/houdini/client/ayon_houdini/startup/otls/ayon_lop_import.hda/ayon_8_8Lop_1lop__import_8_81.0/OnCreated index bd09a7838b..06ccdaa653 100644 --- a/server_addon/houdini/client/ayon_houdini/startup/otls/ayon_lop_import.hda/ayon_8_8Lop_1lop__import_8_81.0/OnCreated +++ b/server_addon/houdini/client/ayon_houdini/startup/otls/ayon_lop_import.hda/ayon_8_8Lop_1lop__import_8_81.0/OnCreated @@ -2,4 +2,5 @@ node = kwargs["node"] hda_module = node.hdaModule() hda_module.setup_flag_changed_callback(node) +node.parm("product_type").lock(True) node.parm("file").lock(True) diff --git a/server_addon/houdini/client/ayon_houdini/startup/otls/ayon_lop_import.hda/ayon_8_8Lop_1lop__import_8_81.0/PythonModule b/server_addon/houdini/client/ayon_houdini/startup/otls/ayon_lop_import.hda/ayon_8_8Lop_1lop__import_8_81.0/PythonModule index f1ee7df56f..4b83cf008e 100644 --- a/server_addon/houdini/client/ayon_houdini/startup/otls/ayon_lop_import.hda/ayon_8_8Lop_1lop__import_8_81.0/PythonModule +++ b/server_addon/houdini/client/ayon_houdini/startup/otls/ayon_lop_import.hda/ayon_8_8Lop_1lop__import_8_81.0/PythonModule @@ -4,5 +4,7 @@ from ayon_houdini.api.hda_utils import ( on_representation_id_changed, on_representation_parms_changed, setup_flag_changed_callback, - get_available_versions + get_available_versions, + get_available_products, + refresh_version )