Skip to content

Commit

Permalink
Merge pull request #11 from ynput/enhancement/houdini_load_asset_lop_…
Browse files Browse the repository at this point in the history
…add_product_selection

Houdini: Asset LOP HDA: Add products drop down menu
  • Loading branch information
BigRoy authored Jun 27, 2024
2 parents f756064 + 791707b commit e5d684a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
40 changes: 40 additions & 0 deletions server_addon/houdini/client/ayon_houdini/api/hda_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit e5d684a

Please sign in to comment.