Files
Nexus/2023/scripts/rigging_tools/ngskintools2/launcher.py
2025-11-24 08:27:50 +08:00

68 lines
2.3 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
ngSkinTools2 启动器
用于从工具架快速启动 ngSkinTools2
"""
import sys
import os
def LaunchNgSkinTools():
"""
启动 ngSkinTools2 主界面
"""
try:
from maya import cmds, mel
# 将当前目录添加到 Python 路径,并使用别名
# 这样 ngSkinTools2 内部的 "from ngSkinTools2.ui" 就能找到模块
current_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_dir)
# 添加父目录到路径
if parent_dir not in sys.path:
sys.path.insert(0, parent_dir)
# 添加当前目录到路径,作为 ngSkinTools2 模块
if current_dir not in sys.path:
sys.path.insert(0, current_dir)
# 在 sys.modules 中创建别名,让 ngSkinTools2 指向 ngskintools2
import rigging_tools.ngskintools2 as ngskintools2_module
sys.modules['ngSkinTools2'] = ngskintools2_module
# 查找并添加插件路径
# ngSkinTools2 插件在 ngskintools2/plug-ins/2023/ 下
plugin_dir = os.path.join(current_dir, 'plug-ins', '2023')
if os.path.exists(plugin_dir):
# 添加插件路径
current_plugin_path = os.environ.get('MAYA_PLUG_IN_PATH', '')
if plugin_dir not in current_plugin_path:
os.environ['MAYA_PLUG_IN_PATH'] = plugin_dir + os.pathsep + current_plugin_path
# 加载插件
if not cmds.pluginInfo('ngSkinTools2', query=True, loaded=True):
try:
cmds.loadPlugin(os.path.join(plugin_dir, 'ngSkinTools2.mll'))
print("ngSkinTools2 plugin loaded successfully")
except Exception as plugin_error:
print(f"Warning: Could not load ngSkinTools2 plugin: {plugin_error}")
else:
print(f"Warning: Plugin directory not found: {plugin_dir}")
# 现在可以导入并打开 UI
from rigging_tools.ngskintools2 import open_ui
open_ui()
print("ngSkinTools2 UI opened successfully")
except Exception as e:
print(f"Failed to open ngSkinTools2: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
LaunchNgSkinTools()