How can I create a new asset library, like what bpy.ops.preferences.asset_library_add()
does, but also get the new library stored in a variable?
The operator just returns {'FINISHED'}
. Normally there's a separate function like D.materials.new()
which returns the created datablock, but I can't find any similar .new()
function for asset libraries which are stored as part of the preferences in C.preferences.filepaths.asset_libraries
.
Feasibly I could store a list of asset libraries, create a new one, and then examine the libraries to see which is not present in the old list, but this seems like a silly workaround.
Edit: I guess it's maybe intentional that this can't be done easily, as you also have to handle saving the user's preferences.
bpy.ops
: The Blender Python fine manual Gotchas section says "Blender’s operators are tools for users to access, that can be accessed with Python too which is very useful."bpy.ops
should be avoided in the case where 1) performance is critical and 2) there exists a low level alternative. If either of these is not true, than by all means usebpy.ops
but be aware of gotchas. $\endgroup$