Get all project assets grouped by type

Is there a way to query all assets in a project and have the results returned in groups based on the asset type? Using python :slight_smile:

In theory this is like a hybrid query of ‘find’ and ‘summarize’ Is this possible?

1 Like

Hey Joker,

What’s the end result you’re looking to achieve? If you just need high level info in aggregate from all the Assets, then the summarize() call is going to be your best bet. If you need specific fields of information from each and every Asset, then find() and parsing through your results will be what you want to use.

Note that you can pass in an order variable with find() to sort the returned results in a particular way. If you ordered by the “Type” field the Assets would all come back with like types together. Let me know how that helps!

PS - Whenever I type “Hey Joker” all I can hear is Gomer Pyle’s wild-eyed delivery from Full Metal Jacket :stuck_out_tongue_winking_eye: .

2 Likes

That is hilarious lol.

Then end goal is to then populate a GUI that has a dropdown for ‘asset type’ and then a secondary area where i display the assets associated with that type. I can always group them on my own. I just figured if there was a way to do this when querying shotgun it would save some time.

The user changes the dropdown for asset type and i then populate the gui with assets of that type.

2 Likes

There’s a couple of ways to go about it, all with their tradeoffs. You could fetch all the Assets preemptively, so as the users click between the different Types, the data is already there to be displayed. This has the drawback of you having to query for potentially a lot of unnecessary data if they only needed to pick one Type, for example. The other idea would be to only run the more tightly scoped query on-demand each time they select a different Type in your UI. This could save query time since you’re just grabbing a sub-set of all Assets.

Based on the total number of Assets you’re querying for, one may be preferred over the other. You could run some quick timing tests to see what, if any differences exist based on your data set.

1 Like