Hello @Easan,
Thank you for reaching out to us. What you want to do is not possible, as there is no way to retrieve the selected asset(s) in "the" Asset Browser. For once because we tend to not expose UIs and their functionalities and because there can be many Asset Browser instances in Cinema 4D. And these instances do not share selection states, so the state is not stored in the asset itself (wich then loops back to the fact that we do not expose UIs).
What you can do is:
- Just use drag and drop. This is the preferred method. I just yesterday made a posting on how to manually handle asset drag drop events (at the example of a tree view, would work similarly in other cases where you have access to drag and drop data). But in most cases, you won't have to do all that, because things like text fields and filename fields have already built in asset drag and drop support. So, you can just add them to your UI and start using them.
- Open your own Asset Browser popup to let the user select an asset, using maxon.AssetManagerInterface.OpenPopup. See the example at the end of this posting for details.
Cheers,
Ferdinand
Code:
"""Demonstrates how to let a user select one or multiple assets with an asset browser popup.
"""
import c4d
import maxon
doc: c4d.documents.BaseDocument # The active document
def OnAssetSelect(data: maxon.DragAndDropDataAssetArray) -> None:
"""Called by the maxon.AssetManagerInterface.OpenPopup call below once the user finalizes his
or her selection.
"""
asset: maxon.AssetDescriptionInterface
url: maxon.Url
# Iterate over each selected asset ...
for asset, url, _ in data.GetAssetDescriptions():
aid: maxon.Id = asset.GetId()
repo: maxon.AssetRepositoryRef = asset.GetRepository()
name: str = asset.GetMetaString(
maxon.OBJECT.BASE.NAME, maxon.Resource.GetCurrentLanguage(), "")
# ... and print some metadata for it.
print (f"{name = }, {aid = }, {url = }, {repo = }")
def main() -> None:
"""
"""
maxon.AssetManagerInterface.OpenPopup(
flags=maxon.ASSETPOPUPOPTIONS.SHOWCATEGORYLIST,
masterFilter=maxon.MASTERFILTER.MEDIA,
filterString="",
title="Select textures to load",
inSelection=[],
outSelection=OnAssetSelect)
if __name__ == '__main__':
main()