Adding to Layout Asset Gallery from Python

   2322   4   3
User Avatar
Member
61 posts
Joined: Oct. 2013
Offline
I'm looking to add to the layout asset gallery via python. I've found:
$HFS/houdini/python2.7libs/husd/assetutils.py

which contains:
def addAsset(asset_file_or_dir_path, thumbnail_file_path=None, asset_name=None)

However regardless of how I run it I never get an asset added. The code I'm running:
import husd.assetutils as au
au.AssetGallery.addAsset('c:/test/toy/toy.usd')

Furthermore, when querying the database directly via sqlite3 to see if everything's working, I get this error after attempting to add an asset via python:
sqlite3.OperationalError: Could not decode to UTF-8 column 'thumbnail' with text ' ╪ α'

Is there a guide on how this should work? Any pointers would definitely be appreciated!
Grant Miller
VFX Supervisor
Ingenuity Studios
User Avatar
Member
18 posts
Joined: Nov. 2013
Offline
The asset gallery panel may not be updated.
I found that Component Output Lop calls hou.qt.AssetGallery().getLocalModel().updateFromSource() after adding an asset
User Avatar
Member
282 posts
Joined: Oct. 2019
Offline
you need to feed it a name as well:

hou.qt.AssetGallery().addAsset("nameOfAsset", filepathForUSD)
Oliver Hotz
Origami Digital
Author of ODTools for Houdini: https://origamidigital.com/cart/index.php?route=product/product&path=59_63&product_id=66 [origamidigital.com]
User Avatar
Member
61 posts
Joined: Oct. 2013
Offline
Thanks for the help!

I can confirm that the following code adds the asset as expected:
hou.qt.AssetGallery.addAsset('toy', 'c:/test/toy/toy.usd', 'c:/test/toy/thumbnail.png')

Is the source for this module somewhere? The arguments don't line up with this function signature from $HFS/houdini/python2.7libs/husd/assetutils.py at all, and all 3 arguments are required:
def addAsset(asset_file_or_dir_path, 
        thumbnail_file_path = None, asset_name = None):
    """ Adds a USD asset to the asset gallery, given the
        asset file or directory, and optionally the thumbnail file and 
        asset name.

        If thumbnail file is not provided or does not exist in a
        given asset directory, it is automatically generated, 
        so that the asset gallery entry always has an icon.

        If asset name is not provided, it is deduced from the file/dir name.
    """

Regardless happy to have it working
Grant Miller
VFX Supervisor
Ingenuity Studios
User Avatar
Member
120 posts
Joined: Jan. 2012
Offline
in H19 there is Component Builder that has it implemented via Python.
Nice and clean code.
Michal Tas Maciejewski @ www.vfxtricks.com
  • Quick Links