How to create a new catalog in the Asset Browser using Python?

Using this code gives an error. How can I create a new catalog?

import bpy

bpy.ops.asset.catalog_new()

I get an error message like this.

Error: Python: Traceback (most recent call last):
File “D:\CG\Work\ShortMovie\Asset\Ch\AKA\Ly\Ly_Ch_AKA_Mdl_v000.000.blend\Text.002”, line 3, in
File “C:\Program Files\blender-3.3.1-stable+v33.b292cfe5a936-windows.amd64-release\3.3\scripts\modules\bpy\ops.py”, line 113, in call
ret = _op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.asset.catalog_new.poll() failed, context is incorrect

1 Like

That operator must be called from an asset browser. The poll method specifically needs:

  • context.space_data.type to be FILE_BROWSER
  • context.space_data.browse_mode to be ASSETS
  • the active asset library to be writable

If you want to call the operator from outside an asset browser (file browser) editor, you either need to find an existing one, or create one before calling the operator.

2 Likes

You can also do it brute force. Find the blender_assets.cats.txt corresponding to your asset library. Append your catalog uuid, name and hierarchy to it in the format : uuid:tree:name. Then save the file, reload the library. You can open an existing asset library text file to see how it’s done inside it.

1 Like

thank you! I made it.

or reuse any of the areas and switch to the assets editor, execute your new catalog operator, and then switch back to previous editor.

Can you rename the catalog afterwards if you do it that way ?