feat: Refactor asset library management and update manifest for improved organization
This commit is contained in:
@@ -10,54 +10,36 @@ from . import menus
|
||||
auto_load.init()
|
||||
|
||||
|
||||
def add_asset_library_if_missing():
|
||||
"""检查并添加Asset Library(如果不存在),使用link导入方式"""
|
||||
# 检查路径是否存在
|
||||
def add_asset_library():
|
||||
"""Add Bioxel asset library, ensuring only one exists by removing duplicates first."""
|
||||
if not NODE_LIB_DIRPATH.exists():
|
||||
print(f"警告: 节点库路径不存在 - {NODE_LIB_DIRPATH}")
|
||||
print(f"Node library path does not exist - {NODE_LIB_DIRPATH}")
|
||||
return
|
||||
|
||||
# 转换为字符串路径用于Blender设置
|
||||
lib_path_str = str(NODE_LIB_DIRPATH)
|
||||
|
||||
# 检查是否已存在该资产库
|
||||
prefs = bpy.context.preferences.filepaths.asset_libraries
|
||||
for lib in prefs:
|
||||
if lib.path == lib_path_str:
|
||||
return # 已存在,无需添加
|
||||
|
||||
# 添加新的资产库,使用link导入方式
|
||||
# Add new library
|
||||
new_lib = prefs.new()
|
||||
new_lib.name = "O Bioxel" # 资产库名称
|
||||
new_lib.path = lib_path_str # 资产库路径(字符串形式)
|
||||
new_lib.import_method = "PACK" # 设置导入方式为link
|
||||
new_lib.name = "O Bioxel"
|
||||
new_lib.path = lib_path_str
|
||||
new_lib.import_method = "PACK"
|
||||
|
||||
print(f"Add Bioxel Nodes library: {lib_path_str}")
|
||||
|
||||
|
||||
def remove_asset_library_if_exists():
|
||||
"""Remove the Bioxel asset library entry if it was added (by path or name)."""
|
||||
# if path missing, nothing to remove
|
||||
lib_path_str = str(NODE_LIB_DIRPATH)
|
||||
prefs = bpy.context.preferences.filepaths.asset_libraries
|
||||
|
||||
# iterate over a snapshot of prefs to safely find index
|
||||
lib_to_remove = None
|
||||
for i, lib in enumerate(list(prefs)):
|
||||
for lib in list(prefs):
|
||||
try:
|
||||
if lib.path == lib_path_str:
|
||||
lib_to_remove = lib
|
||||
break
|
||||
if "Bioxel" in lib.name or lib.path == lib_path_str:
|
||||
prefs.remove(lib)
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
if lib_to_remove is not None:
|
||||
try:
|
||||
prefs.remove(lib_to_remove)
|
||||
print(f"Removed Bioxel Nodes library: {lib_path_str}")
|
||||
except Exception as e:
|
||||
print(f"Warning: failed to remove Bioxel node library: {e}")
|
||||
|
||||
|
||||
def register():
|
||||
pcoll = previews.new()
|
||||
@@ -90,7 +72,8 @@ def register():
|
||||
|
||||
auto_load.register()
|
||||
menus.add()
|
||||
add_asset_library_if_missing()
|
||||
remove_asset_library_if_exists()
|
||||
add_asset_library()
|
||||
|
||||
|
||||
def unregister():
|
||||
|
||||
Reference in New Issue
Block a user