Here's an asnwer for adding a list of Asset pathes:
if you need to erase the list of assets before just use this code
for i in range(len(bpy.context.preferences.filepaths.asset_libraries)):
bpy.ops.preferences.asset_library_remove(index=0)
by default blender takes the name of the directory as Name:
1.if you want a different name for the Name : for each tupple in list_pathes just put in the tupple the name you want to appear in the list first and the path of the directory where is your blend file containing assets
list_pathes = [
("Zozo LE BOBO",
"D:\- 4. Software Data\- Blender\Assets Library\cs boulons vis et formes"),
("RAGNAGNA",
"D:\- 4. Software Data\- Blender\Assets Library\cs materials"),
("zglurb",
"D:\- 4. Software Data\- Blender\Assets Library\cs geometry nodes")
]
offset = len(bpy.context.preferences.filepaths.asset_libraries)
index = offset
for path in list_pathes:
bpy.ops.preferences.asset_library_add(directory = path[1])
# give a name to your asset dir
bpy.context.preferences.filepaths.asset_libraries[index].name = path[0]
index += 1
2.if you don't need a different name for your asset you can use this simple code
list_pathes = [
"D:\- 4. Software Data\- Blender\Assets Library\cs boulons vis et formes",
"D:\- 4. Software Data\- Blender\Assets Library\cs materials",
"D:\- 4. Software Data\- Blender\Assets Library\cs geometry nodes"
]
for path in list_pathes:
bpy.ops.preferences.asset_library_add(directory = path)
3.if you don't need a different name for your asset and all your assets are in folders nested in one specific folder
path = "D:\- 4. Software Data\- Blender\Assets Library"
for i in os.scandir(path):
if i.is_dir():
print('Folder: ' + i.path)
bpy.ops.preferences.asset_library_add(directory = i.path)
bpy.context.preferences.filepaths.asset_libraries
docs.blender.org/api/current/bpy.types.UserAssetLibrary.html $\endgroup$