#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ SUW Load Module - Python翻译版本 原文件: SUWLoad.rb 用途: 加载所有SUWood相关模块 """ import sys import os from pathlib import Path # 添加当前目录到Python路径 current_dir = Path(__file__).parent sys.path.insert(0, str(current_dir)) # 导入所有SUWood模块 try: from . import suw_constants from . import suw_core from . import suw_client from . import suw_observer from . import suw_unit_point_tool from . import suw_unit_face_tool from . import suw_unit_cont_tool from . import suw_zone_div1_tool from . import suw_menu print("✅ SUWood 所有模块加载成功") except ImportError as e: print(f"⚠️ 模块加载警告: {e}") print("部分模块可能尚未创建或存在依赖问题") # 模块列表(对应原Ruby文件) REQUIRED_MODULES = [ 'suw_constants', # SUWConstants.rb 'suw_core', # SUWImpl.rb (已重构为suw_core) 'suw_client', # SUWClient.rb 'suw_observer', # SUWObserver.rb 'suw_unit_point_tool', # SUWUnitPointTool.rb 'suw_unit_face_tool', # SUWUnitFaceTool.rb 'suw_unit_cont_tool', # SUWUnitContTool.rb 'suw_zone_div1_tool', # SUWZoneDiv1Tool.rb 'suw_menu' # SUWMenu.rb ] def check_modules(): """检查所有必需模块是否存在""" missing_modules = [] for module_name in REQUIRED_MODULES: module_file = current_dir / f"{module_name}.py" if not module_file.exists(): missing_modules.append(module_name) if missing_modules: print(f"❌ 缺少模块: {', '.join(missing_modules)}") return False else: print("✅ 所有必需模块文件都存在") return True def load_all_modules(): """加载所有模块""" loaded_modules = [] failed_modules = [] for module_name in REQUIRED_MODULES: try: __import__(f'blenderpython.{module_name}') loaded_modules.append(module_name) except ImportError as e: failed_modules.append((module_name, str(e))) print(f"✅ 成功加载模块: {len(loaded_modules)}/{len(REQUIRED_MODULES)}") if failed_modules: print("❌ 加载失败的模块:") for module, error in failed_modules: print(f" - {module}: {error}") return loaded_modules, failed_modules if __name__ == "__main__": print("🚀 SUWood Python模块加载器") print("=" * 40) # 检查模块文件 check_modules() # 尝试加载所有模块 loaded, failed = load_all_modules() print(f"\n📊 加载结果: {len(loaded)}/{len(REQUIRED_MODULES)} 个模块成功加载")