`ArResolver::OpenAsset` in python

Hello. I noticed that OpenAsset is not a part of the python bindings of ArResolver. Is there any reason to not support this? It seems like ArAsset has enough information to support python’s io interfaces.

Potential workflow–

attribute = prim.GetAttribute('path_to_json_file')
jsonAssetPath = attribute.Get()
# jsonAssetPath may or may not have been resolved to a file path
jsonAsset = resolver.OpenAsset(jsonAssetPath.resolvedPath)
# `ArAsset`'s `Read` is used to get the bytes.

We agree, @nvmkuruc … more of a “not that urgent at the time” thing that dropped off the radar. We’d definitely be up for a PR - thanks!

Thanks! We’ll work on getting one put together.

For completeness, we have submitted a Pull Request to expose this ArResolver.OpenAsset(resolvedPath) API to Python: Expose bindings to `ArAsset`, to support performing `OpenAsset(resolvedPath)` from Python by philsawicki · Pull Request #3145 · PixarAnimationStudios/OpenUSD · GitHub

The proposed changes aim to expose workflows such as the following (see referenced PR for details):

# [...]

# Retrieve the content of the asset at the given `Ar.ResolvedPath`:
with Ar.GetResolver().OpenAsset(resolvedPath=resolved_asset_path) as asset:
    print(f'JSON asset data: {asset.GetBuffer()}')
1 Like