Files
Nexus/2023/scripts/animation_tools/studiolibrary/launcher.py
2025-11-24 23:42:22 +08:00

79 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Studio Library Launcher
用于从工具架快速启动 Studio Library
支持所有 Maya 版本2017-2026+
"""
import sys
import os
def LaunchStudioLibrary():
"""
启动 Studio Library 主界面
自动检测 Maya 版本和 Qt 绑定
Returns:
LibraryWindow: Studio Library 窗口实例,失败时返回 None
"""
try:
# 获取 Studio Library 路径
current_dir = os.path.dirname(os.path.abspath(__file__))
# 关键:直接将内层 studiolibrary 子目录放到 sys.path 最前面
# 这样 import studiolibrary 会直接找到内层的,避免循环导入
studiolibrary_subdir = os.path.join(current_dir, 'studiolibrary')
# 临时保存并清理 sys.path避免外层包干扰
original_path = sys.path[:]
sys.path.insert(0, studiolibrary_subdir)
# 添加其他必要的路径
for subdir in ['studiolibrarymaya', 'mutils', 'studioqt', 'studiovendor']:
subdir_path = os.path.join(current_dir, subdir)
if subdir_path not in sys.path:
sys.path.insert(0, subdir_path)
# 导入 Studio Library现在会找到内层的
import studiolibrary
# 打印版本信息
print("Studio Library version: " + str(studiolibrary.version()))
# 检测 Maya 环境
try:
import maya.cmds
maya.cmds.about(batch=True)
print("Studio Library: Running in Maya environment")
except (ImportError, AttributeError):
print("Studio Library: Running in standalone mode")
# 启动主窗口
window = studiolibrary.main()
print("Studio Library launched successfully")
return window
except Exception as e:
print("Failed to launch Studio Library: " + str(e))
import traceback
traceback.print_exc()
# 提供详细的调试信息
print("\n=== Debug Information ===")
print("Current directory: " + os.path.dirname(os.path.abspath(__file__)))
print("sys.path entries:")
for i, path in enumerate(sys.path[:10]):
print(" [" + str(i) + "] " + path)
print("=========================\n")
return None
if __name__ == "__main__":
LaunchStudioLibrary()