diff --git a/src/bioxelnodes/__init__.py b/src/bioxelnodes/__init__.py index 9547761..d807684 100644 --- a/src/bioxelnodes/__init__.py +++ b/src/bioxelnodes/__init__.py @@ -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(): diff --git a/src/bioxelnodes/assets/O Bioxel/BioxelNodes.blend b/src/bioxelnodes/assets/O Bioxel/BioxelNodes.blend deleted file mode 100644 index 5db983f..0000000 --- a/src/bioxelnodes/assets/O Bioxel/BioxelNodes.blend +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:6c0cdfc0e9a37d0e559691fd8893697e1236ddbf3d31b6165ea72e7dcffada2f -size 14083935 diff --git a/src/bioxelnodes/assets/O_Bioxel/O_Bioxel_Nodes.blend b/src/bioxelnodes/assets/O_Bioxel/O_Bioxel_Nodes.blend new file mode 100644 index 0000000..3d8f98a --- /dev/null +++ b/src/bioxelnodes/assets/O_Bioxel/O_Bioxel_Nodes.blend @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1699f2d06cdb25a935abc97e7f4e2c72164f8fb741e655a32b451c67b2e61672 +size 13787325 diff --git a/src/bioxelnodes/assets/O Bioxel/blender_assets.cats.txt b/src/bioxelnodes/assets/O_Bioxel/blender_assets.cats.txt similarity index 100% rename from src/bioxelnodes/assets/O Bioxel/blender_assets.cats.txt rename to src/bioxelnodes/assets/O_Bioxel/blender_assets.cats.txt diff --git a/src/bioxelnodes/blender_manifest.toml b/src/bioxelnodes/blender_manifest.toml index 9fb8990..bfe79e6 100644 --- a/src/bioxelnodes/blender_manifest.toml +++ b/src/bioxelnodes/blender_manifest.toml @@ -4,7 +4,7 @@ id = "bioxelnodes" version = "2.0.0" name = "Bioxel Nodes" tagline = "For scientific volumetric data visualization in Blender" -maintainer = "Ma Nan " +maintainer = "Nan " type = "add-on" website = "https://omoolab.github.io/BioxelNodes/latest" @@ -14,7 +14,32 @@ license = ['SPDX:GPL-3.0-or-later'] copyright = ["2024 OmooLab"] platforms = ["windows-x64"] -wheels = ["./wheels/contourpy-1.3.3-cp311-cp311-win_amd64.whl", "./wheels/contourpy-1.3.3-cp313-cp313-win_amd64.whl", "./wheels/cycler-0.12.1-py3-none-any.whl", "./wheels/fonttools-4.63.0-cp311-cp311-win_amd64.whl", "./wheels/fonttools-4.63.0-cp313-cp313-win_amd64.whl", "./wheels/h5py-3.16.0-cp311-cp311-win_amd64.whl", "./wheels/h5py-3.16.0-cp313-cp313-win_amd64.whl", "./wheels/kiwisolver-1.5.0-cp311-cp311-win_amd64.whl", "./wheels/kiwisolver-1.5.0-cp313-cp313-win_amd64.whl", "./wheels/lxml-6.1.1-cp311-cp311-win_amd64.whl", "./wheels/lxml-6.1.1-cp313-cp313-win_amd64.whl", "./wheels/matplotlib-3.10.7-cp311-cp311-win_amd64.whl", "./wheels/matplotlib-3.10.7-cp313-cp313-win_amd64.whl", "./wheels/mrcfile-1.5.1-py2.py3-none-any.whl", "./wheels/packaging-26.2-py3-none-any.whl", "./wheels/pillow-11.2.1-cp311-cp311-win_amd64.whl", "./wheels/pillow-11.2.1-cp313-cp313-win_amd64.whl", "./wheels/pyometiff-1.0.0-py3-none-any.whl", "./wheels/pyparsing-3.3.2-py3-none-any.whl", "./wheels/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", "./wheels/simpleitk-2.5.5-cp311-abi3-win_amd64.whl", "./wheels/six-1.17.0-py2.py3-none-any.whl", "./wheels/tifffile-2024.7.24-py3-none-any.whl", "./wheels/transforms3d-0.4.2-py3-none-any.whl"] +wheels = [ + "./wheels/contourpy-1.3.3-cp311-cp311-win_amd64.whl", + "./wheels/contourpy-1.3.3-cp313-cp313-win_amd64.whl", + "./wheels/cycler-0.12.1-py3-none-any.whl", + "./wheels/fonttools-4.63.0-cp311-cp311-win_amd64.whl", + "./wheels/fonttools-4.63.0-cp313-cp313-win_amd64.whl", + "./wheels/h5py-3.16.0-cp311-cp311-win_amd64.whl", + "./wheels/h5py-3.16.0-cp313-cp313-win_amd64.whl", + "./wheels/kiwisolver-1.5.0-cp311-cp311-win_amd64.whl", + "./wheels/kiwisolver-1.5.0-cp313-cp313-win_amd64.whl", + "./wheels/lxml-6.1.1-cp311-cp311-win_amd64.whl", + "./wheels/lxml-6.1.1-cp313-cp313-win_amd64.whl", + "./wheels/matplotlib-3.10.7-cp311-cp311-win_amd64.whl", + "./wheels/matplotlib-3.10.7-cp313-cp313-win_amd64.whl", + "./wheels/mrcfile-1.5.1-py2.py3-none-any.whl", + "./wheels/packaging-26.2-py3-none-any.whl", + "./wheels/pillow-11.2.1-cp311-cp311-win_amd64.whl", + "./wheels/pillow-11.2.1-cp313-cp313-win_amd64.whl", + "./wheels/pyometiff-1.0.0-py3-none-any.whl", + "./wheels/pyparsing-3.3.2-py3-none-any.whl", + "./wheels/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", + "./wheels/simpleitk-2.5.5-cp311-abi3-win_amd64.whl", + "./wheels/six-1.17.0-py2.py3-none-any.whl", + "./wheels/tifffile-2024.7.24-py3-none-any.whl", + "./wheels/transforms3d-0.4.2-py3-none-any.whl", +] [permissions] files = "Import/export volume data from/to disk" diff --git a/src/bioxelnodes/constants.py b/src/bioxelnodes/constants.py index 1fa5afc..6a7c393 100644 --- a/src/bioxelnodes/constants.py +++ b/src/bioxelnodes/constants.py @@ -1,9 +1,11 @@ from pathlib import Path +NODE_LIB_FILENAME = "O_Bioxel_Nodes.blend" + NODE_LIB_DIRPATH = Path(Path(__file__).parent, "assets/O_Bioxel").resolve() LATEST_NODE_LIB_PATH = Path(NODE_LIB_DIRPATH, - "BioxelNodes.blend").resolve() + NODE_LIB_FILENAME).resolve() PREVIEW_COLLECTIONS = {} diff --git a/src/bioxelnodes/node.py b/src/bioxelnodes/node.py index b09b66b..f59b06c 100644 --- a/src/bioxelnodes/node.py +++ b/src/bioxelnodes/node.py @@ -2,7 +2,7 @@ from pathlib import Path import bpy # LookupError replaced with built-in LookupError -from .constants import LATEST_NODE_LIB_PATH +from .constants import LATEST_NODE_LIB_PATH, NODE_LIB_FILENAME def move_node_to_node(node, target_node, offset=(0, 0)): @@ -105,7 +105,7 @@ def add_bioxel_node(name: str): bpy.ops.object.modifier_add_node_group( asset_library_type="CUSTOM", asset_library_identifier="O Bioxel", - relative_asset_identifier=f"BioxelNodes.blend\\NodeTree\\{name}", + relative_asset_identifier=f"{NODE_LIB_FILENAME}\\NodeTree\\{name}", ) bpy.ops.object.modifier_remove(modifier=name) try: