Asset Browser Utilities : Batch Operations : Mark/Unmark, Export, tweak Metadata, manage Previews

I’ve been working on an utility add-on to help organizing an existing library of files, because doing it by hand is very time consuming.

This is of course made for 3.0 and up.

The script was beginning to get a little too noodly for my taste so I’ve decided to make it into an add-on with structured sub-modules, which means it can’t be simply run in the script editor like a regular script anymore. So I won’t be pasting the code here anymore, but it is still available for free on my github :

Release (Please download asset_browser_utilities_x.y.z.zip, not the source code files) :

Readme (follow link for details) :

If you encounter any bug or would like to see a feature implemented, please send an issue on the github page or on this thread.

19 Likes

Thanks for sharing.

Thanks ! After some testing the first version wasn’t working for files with multiple objects so I just updated it. Should work now. Also added an option (checkbox) to choose if the parser should recursively search for files in the subfolders of the selected folder.

Cheers

1 Like

@Gorgious Thanks for the addon, I will check this out shortly!

So as a matter of precaution, when you say that the files should not contain too many assets, does this also concern the folders themselves? I want to mark all 35gb worth of assets, each located in their own .blend file within a folder. Do I need to split this up into subfolders or would the script be okay with crunching through all of this in one go?

Does your script filter the contents of the folder for object, materials, images, brushes, etc? The purpose for which I want to use it is to mark all vegetation objects I downloaded from a library as asset, not necessarily all the materials or textures contained within the file. Preferably, those should only be associated to the objects themselves.

In fact since my latest update this warning doesn’t apply anymore. You just have to be aware that if you want to generate custom previews when marking the assets, you have to wait some time for it to finish before marking the next asset, I’ve arbitrarily set the wait time to 1,0 second so if say you have 10000 assets to add to your library and generate their preview, it will take roughly 3 hours.

It’s is perfectly fine and the intended workflow to use the script on folders and subfolders containing many .blend files which in turn individually contain a low number of objects to mark as assets.

By default only the objects are marked as assets. It would be a nice addition to be able to select which data types would be added as assets, I’ll add it to the todo list :slight_smile:

So long story short, you should just be able to run this on your folder (maybe do a test run with a small subset of files first to avoid having to clean up some mess if things go south ^^) and it’ll automatically mark objects as assets and generate the previews. Count roughly ~1 second per asset.

Also be aware of another caveat which I don’t know how to solve gracefully since I think automatically deleting files is a bad idea : Since you need to save individual files in order to register the assets in the asset library, if you enabled “Save Version” in the “Save & Load” preferences (which creates .blend001, .blend002, etc. versions of your file when you save), it will create quasi-duplicate files for each file in your library, effectively doubling its size in memory… So maybe set it to 0 before running the script, and remember to set it back to the previous value if you use the backup feature.

Also >< the previews do take extra space in memory, I’m not sure exactly how much but it will add to your library size in memory.

Do not hesitate to ping me if you’re having any trouble using it !

Cheers

1 Like

Thank you for the detailed response. This is going to be such a major time saver, I was afraid there would be no such thing available, so really glad someone pointed this out to me! I’ll be sure to do a test run first this week.

Do you think it is possible to create a prompt with the save version set as a reminder? As in let the script check what setting is used for “save version” before proceeding and to only have it proceed with ‘0’ set. When done, it should open the preferences in the save version tab so you can set it back to what it was. I think it’s best not to directly alter the preferences, as you don’t want to risk a bug getting in the script that would ruin saving when you’re not cognisant of this. Just a thought.

I don’t know how well this scales for larger files (500Mb trees), but if you could predict the timing this well, a prompt/ progress bar could be nice as an indication. I’ll be sure to let it run when I am away from my PC anyways. :slight_smile:

Just out of curiosity, do the previews store in the .blend files within the asset library (the folder) themselves? And is that what is causing the slight size inflation? It’s really nice to have these thumbnails and files associated.

OK the changes where not that difficult so I just pushed 2 changes to the code :

  • You can now only mark assets without generating the preview
  • You can now select which data type you want to mark as assets, in 3.0 it’s only possible to mark Objects, Actions, Worlds and Materials.

Do you think it is possible to create a prompt with the save version set as a reminder? As in let the script check what setting is used for “save version” before proceeding and to only have it proceed with ‘0’ set. When done, it should open the preferences in the save version tab so you can set it back to what it was. I think it’s best not to directly alter the preferences, as you don’t want to risk a bug getting in the script that would ruin saving when you’re not cognisant of this. Just a thought.

Yeah I need to think this through very carefully. I definitely don’t want the script to change the preferences globally, and not even temporarily since if for some reason it crashes mid way it won’t reset the value back. I could automatically detect if a new file has been generated and deleting it afterwards, but again this needs to be done carefully so as not to erase unintended files. I’ll think about it :slight_smile:

I don’t know how well this scales for larger files (500Mb trees), but if you could predict the timing this well, a prompt/ progress bar could be nice as an indication. I’ll be sure to let it run when I am away from my PC anyways.

Well I can predict it because I set the interval to 1.0 second in the code ! However I have quite a beefy PC so it’s possible on some lower end computers and with complex objects that the preview takes more than 1 second to generate, in which case I’ll add an option to increase the interval. It doesn’t take into account the time it takes Blender to actually open the file nor save it afterwards, though but it depends on a lot of factors so it’s impossible to predict.

Just out of curiosity, do the previews store in the .blend files within the asset library (the folder) themselves? And is that what is causing the slight size inflation? It’s really nice to have these thumbnails and files associated.

As far as I know they’re stored in the .blend file where the asset was marked, so yeah in theory you can send the library files to someone else and they’ll have the preview generated already. Didn’t test it though so I may be wrong :stuck_out_tongue_closed_eyes:

Cheers

1 Like

Version 0.0.4 :

  • Added the option to prevent creating a backup file when saving files. Be careful with it, there is no confirmation and the backup files are deleted permanently.
  • Added option to not overwrite items that have already been marked as assets. Can speed up things if a file already contains assets
  • Added option to batch clear assets instead of marking them as assets
  • Fixed hard crash when batch generating assets (disabled info messages for now. Please remember to enable system console before using the addon)

Thanks a lot, it works extremely well. Much faster than I expected too!

Despite the remove backup being turned on, it saved 3 backups for 299 files:

I also noticed that the largest files failed to render the thumbnails:


E: This happens when the interval of the script is too short for it to save the thumbnail. Manually increasing the time within the script resolves the issue.

Perhaps, in order to mitigate this, could the script identify files for which no thumbnail/ preview was generated? Then you’d be able to go over those once more with an increased interval timer.
And, if possible, could you add the interval to the options menu?

E: Would you consider moving the script from File> Import in the main toolbar to the assetbrowser toolbar? If possible, the script would be more closer at hand.

Hey ! I’ve released a new version. You can check it out and see if it’s generating correctly on bigger assets ?

For the remaining backup files, I don’t know for sure, I’ll have to investigate if it keeps happening with the recent changes.

Cheers !

Hey, thanks I’ll try to test it this week.

With Sybren Stüvel’s aid, I have found another reason for previews that were missing. It turns out that if an asset’s scale was modified, but not applied, some assets won’t generate previews. In my case, this was caused by a unit scale setting of 0,01 which was in turn applied to the assets too. However, most assets generated a preview just fine, even within the same plant species and even with the scaling left un-applied.

Unit scale

So it may be beneficial to have an option to reset asset’s scale or to apply it within the addon.

Thanks for the feedback !

I’m a bit hesitant to change the transform or unit scale values since they can have a bunch of unforeseen effects and since the script is deleting the backup file, we might mangle scenes irremediably, and I don’t want to have to deal with that crowd. :stuck_out_tongue_closed_eyes:

I’ve been testing for a bit and I couldn’t reproduce the problem, so it’s hard to pinpoint exactly what causes it as you said.

It looks like it is a known issue on Blender’s side so they might already be working on fixing it in one of the next releases. I’m putting it on the backburner in the meantime.

Cheers !

1 Like

Yeah I can imagine. Adjusting transforms would only be applicable for single asset files from a library — and those should all have their scale applied. :+1:

I don’t want to add too much features to this add-on to keep the scope relevant but this is a really good idea for a standalone script, and it would be pretty easy to do I think. I’ll start the groundworks if you’re interested !

Cheers

I can imagine, the script already works wonders as is!

Yes please, if you are interested in creating such a batch script, I would be very interested. I do need to go over my asset library anyways to correct for the scale… These sorts of batch operations are just the things Blender needs right now to be more useful for getting more serious work done.

A couple of things that come to mind right now for the new script are options to:

  1. Apply scale, rotation and location (separate options for each)
  2. Clear scale, rotation and location (separate options for each)
  3. Automatically scale assets by a factor X.
  4. Move objects by their origin to 0,0,0. This is for single asset files and could be named “Align to world origin” This is in case an object’s location was applied while it was not located at the origin.
  5. Possibly, but doubtful whether you’d want to batch apply this: align objects along the X or Y axis, so you could have a bunch of assets that can be distributed with roughly equal spacing.

It may also be interesting to be able to save objects marked as asset to a new file, so you could store this file within your asset library without the unnecessary bloat from other objects in the .blend file. That way, it also becomes easier to share ‘asset’ files with others.
That’s all the thinking for me for now. Thanks for taking my requests into account!

Awsome to see the new changes, (including the header) wasn’t aware you already implemented this!

By the way, there’s a bug that people may want to be aware of regarding preview generation and shaders that were selected:

This bug also occurs when a shader node was selected and deselected prior to marking an asset. Sybren Stüvel is aware of this and it is currently under discussion with the other Asset Browser devs. Also, I linked this thread in the chat, so they can take it into account for additional Asset Browser features once they get to it, since your work is such a great example of how it should work. :ok_hand:

Hey ! I’ll start thinking about it, looks like a handy tool to develop ! :slight_smile:

In the meantime I’ve worked on polishing the add-on a bit. It’s a wild ride but I learn a LOT !!

  • Renamed the addon to Asset Browser Utilities. This will mess up all the links to my github but I’ll try to hunt the problematic links.
  • You can now filter items by name (prefix, contains, or suffix) when batch generating from library
  • Optimized preview generation, it should be much faster for files with a lot of assets
  • You can now export assets from current file to existing file or new file (TODO : add functionality to whole library) with filtering by type, name or selection state
1 Like

If assets are loaded from backup blend files, please report this as a bug.

I think this part was not very clear in my explanation. :slight_smile:

What I meant is that in order to mark assets in file B to be used in file A, B has to be saved after the assets were marked. If you enabled “Save Version”, it will automatically create a new backup file, which is normal and expected behaviour. But I don’t think users want that when just batch-marking their assets, since usually they are very heavy files and in their final state, so it doesn’t really make sense to keep backup files there.

1 Like

Best workaround I found is to mark something as asset and then save it via KitOPS as asset in KitOPS library folder. This folder path you can use as AssetBrowser path.
Doesn’t help me with batch importing because my files are all scenes with many meshes inside. So batch importing them marks every … as asset and then you have a library with thousands of assets flying around belonging to one jobs mesh…(isn’t helpful at all)

There should be libraries for material, mesh, groups, etc…
And when you are in a scene and select and mark something as asset THEN with the next button it get’s saved with a user given name to the library it belongs.
Means we end up with Library files and the information where the material, mesh, group,… is located and stored in what file.
Maybe apending an as asset marked, to another file containing the same sort of materials for example.

That would be small & quick accessable library database files, and the saved assets in single or multi asset files.
And the part of .blend1 ; .blend2 can be solved this way as part of a seperate save action apart from backup preferences setup.

AND that would terminate the fact that the asset-file of an asset in the browser (User Library) has to be opened to be sorted into another category in your blender asset browser…

PLUS the thumbnails could get the same speedscript overhaul, KitOPS uses to very quickly load the whole thumbnail asset/material … catalog.

Anyways, still dreaming…