Is it possible to build a TreeView from a user database?
-
I have multiple Redshift materials (defined as a database) that I'd like to load into the application and show to the user in a GeDialog.
I have successfully loaded the database into the application, but it is not clear to me how to traverse the database such that I am able to build up a tree view structure that can be used to navigate the various catetories/assets in the database.
Using the GetUserPrefsRepository function, I can search for a given category or asset - but only if I know it's ID ahead of time.
If I know the top level category, is it possible to traverse the repository from that point and build up a TreeView to represent those assets?
-
Hello @jpheneger,
Thank you for reaching out to us. I would recommend having a look at the Asset API Handbook as it provides examples for most basic to intermediate Asset API related tasks.
- You can search in the user preferences repository, as it is the union of (allmost) all repositories, but when you want to optimize things, especially when you want to filter out all assets that are not located in your custom database, you should construct a repository for your user data base alone.
- In Asset API: Asset Metadata I showed traversal by category, but that is usually not what you want to do, as this is potentially ambiguous.
- If you want to search for all asset types, all asset instances, or all versions of an asset in a repository, you must simply null the respective
Id
. I would recommend having a look at the three asset search examples in Asset API: Asset Databases.
If I know the top level category, is it possible to traverse the repository from that point and build up a TreeView to represent those assets?
Assets are not intrinsically organized in a hierarchy so that one could traverse them naturally in that manner. Instead, the Asset API is simply a database where all items have a category field, and categories are assets themselves and therefore also have such field. If you want a tree data structure for your assets, you will first have to search for all assets in your repo that are of the asset type category which also do not have a parent category, i.e., are "root level" categories. From there on you can then branch out, by seraching for other assets being parented to these assets. The Asset API: Asset Metadata category examples should get you started on how things work. When you are only after a selection window for assets, i.e., an Asset Browser popup, using maxon::AssetManagerInterface::OpenPopup is probably going to be easier than doing things from scratch.
Cheers,
Ferdinand -
Hello @jpheneger,
without further questions or postings, we will consider this topic as solved by Monday 05/06/2023 and flag it accordingly.
Thank you for your understanding,
Maxime.