Python Asset Gallery Data Source Issue

   549   2   0
User Avatar
Member
3 posts
Joined: Jan. 2015
Offline
Hello!

I'm trying to expand on a tool I created a couple of months ago by adding a selected list of assets to the Layout Asset Gallery via Python. I've pretty much gotten everything down except for the thumbnail portion of this code snippet:

(This is an example code)

import hou

ag = hou.AssetGalleryDataSource('C:\\Users\\joeshmoe\\Desktop\\test.db')

label = 'Sphere'
file = 'C:\\Users\\joeshmoe\\Desktop\\sphere.abc'
thumbnail = b'C:\\Users\\joeshmoe\\Desktop\\sphere.jpg'

ag.addItem(label, file, thumbnail)

ag.saveAs('C:\\Users\\joeshmoe\\Desktop\\test.db')

When I reload the .db file the asset does show up in my gallery, however there is no thumbnail like you would anticipate. The path and label are all populated but not the thumbnail. It's wanting the path converted to bytes in the string but I'm not sure why.

Is there something I'm doing incorrectly or is there something I need to add?

While I'm here, is there any way of refreshing/reloading the Layout Asset Gallery pane tab with python? It doesn't automatically populate the gallery when I use the script so I'm wondering if I can just reload the db file with some code.

Thanks!
Edited by Animationem - Jan. 4, 2024 19:57:51
User Avatar
Member
7 posts
Joined: March 2018
Offline
I used the software DB Browser for SQLite to view the db database and found that thumbnail is a BLOB type, not a file path. I used the following code to successfully generate assets with thumbnails, I hope it can help you.
ag = hou.AssetGalleryDataSource("H:/library/houdini/assetGallery.db")


def open_image_as_bytes(file_path):
    with open(file_path, 'rb') as f:
        return f.read()

label = 'Baskets'
filepath = 'H:/library/meshusd/Baskets/Baskets_main.usda'
thumbpath = 'H:/library/meshusd/Baskets/thumbnail.png'

ag.addItem(label, filepath, open_image_as_bytes(thumbpath))

ag.saveAs('H:/library/houdini/assetGallery.db')
User Avatar
Member
3 posts
Joined: Jan. 2015
Offline
AAaronLi
I used the software DB Browser for SQLite to view the db database and found that thumbnail is a BLOB type, not a file path. I used the following code to successfully generate assets with thumbnails, I hope it can help you.
ag = hou.AssetGalleryDataSource("H:/library/houdini/assetGallery.db")


def open_image_as_bytes(file_path):
    with open(file_path, 'rb') as f:
        return f.read()

label = 'Baskets'
filepath = 'H:/library/meshusd/Baskets/Baskets_main.usda'
thumbpath = 'H:/library/meshusd/Baskets/thumbnail.png'

ag.addItem(label, filepath, open_image_as_bytes(thumbpath))

ag.saveAs('H:/library/houdini/assetGallery.db')


Hey AAronLi! Sorry for getting back to this so late, I wasn't notified I got a response. This worked like a charm, thanks so much!
  • Quick Links