Asset Gallery / Asset Catalog: HOM methods

   204   2   0
User Avatar
Member
6 posts
Joined: Jan. 2015
Offline
Hi,

does anyone of you have a pointer on how to get to the selected asset(s) in the assetCatalog?
I found that there are python functions to get an entry by providing the asset name but I would like to get the selected items.

thank you very much!
User Avatar
Member
154 posts
Joined: June 2019
Offline
i'm not aware of public api but here is the script i'm using

from __future__ import annotations

from dataclasses import dataclass
from typing import Any

import hou


@dataclass
class UsdAsset:
    id: str
    filepath: str
    name: str
    data: bytes


def get_gallery_pane() -> hou.PythonPanel | None:
    py_panels: tuple[hou.PythonPanel] = (
        pane for pane in hou.ui.paneTabs() if pane.type() == hou.paneTabType.PythonPanel
    )
    return next((pane for pane in py_panels if pane.label() == "Asset Catalog"), None)


def gallery_widget() -> Any | None:
    gallery_pane = get_gallery_pane()
    if not gallery_pane:
        return None
    widget = gallery_pane.activeInterfaceRootWidget()._ag
    return widget


def get_asset(data_source: hou.AssetGalleryDataSource, id: str) -> UsdAsset | None:
    if not id:
        return None

    filepath = data_source.filePath(id)
    if not filepath:
        return None

    return UsdAsset(
        id=id,
        filepath=data_source.filePath(id),
        name=data_source.label(id),
        data=data_source.blindData(id),
    )


def get_selected_assets() -> list[UsdAsset]:
    widget = gallery_widget()
    if not widget:
        return []

    data_source: hou.AssetGalleryDataSource = hou.ui.sharedLayoutDataSource()

    selected_ids: list[str] = widget.getSelectedIds()
    return [get_asset(data_source, asset_id) for asset_id in selected_ids]

get_selected_asset would return anything selected in the widget (multi-select is supported)

data bytes is a blob from asset database, currently it used by solaris to determine variant of the asset so on insertion to stage it can set the variant for the asset
User Avatar
Member
6 posts
Joined: Jan. 2015
Offline
Hi elovikov,

thank you so much for providing your script!
I can confirm that I am able to get the ids, names, filepaths with your script.
  • Quick Links