Update
This commit is contained in:
@@ -5,6 +5,10 @@
|
|||||||
Studio Library Wrapper Module
|
Studio Library Wrapper Module
|
||||||
用于简化 Studio Library 的导入和使用
|
用于简化 Studio Library 的导入和使用
|
||||||
支持 Maya 2017-2026+ 所有版本
|
支持 Maya 2017-2026+ 所有版本
|
||||||
|
|
||||||
|
使用方法:
|
||||||
|
import animation_tools.studiolibrary
|
||||||
|
animation_tools.studiolibrary.show()
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@@ -13,52 +17,40 @@ import os
|
|||||||
# 获取当前目录
|
# 获取当前目录
|
||||||
_current_dir = os.path.dirname(os.path.abspath(__file__))
|
_current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
# 确保所有子模块路径都在 sys.path 中
|
# 全局变量用于存储导入的模块
|
||||||
_required_paths = [
|
_studiolibrary_module = None
|
||||||
_current_dir,
|
__version__ = "2.20.2"
|
||||||
os.path.join(_current_dir, 'studiolibrary'),
|
|
||||||
os.path.join(_current_dir, 'studiolibrarymaya'),
|
def _ensure_studiolibrary_loaded():
|
||||||
os.path.join(_current_dir, 'mutils'),
|
"""确保 studiolibrary 模块已加载"""
|
||||||
os.path.join(_current_dir, 'studioqt'),
|
global _studiolibrary_module
|
||||||
os.path.join(_current_dir, 'studiovendor'),
|
|
||||||
|
if _studiolibrary_module is not None:
|
||||||
|
return _studiolibrary_module
|
||||||
|
|
||||||
|
# 添加所有必要的路径
|
||||||
|
_inner_studiolibrary = os.path.join(_current_dir, 'studiolibrary')
|
||||||
|
for _subdir in ['studiolibrary', '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)
|
||||||
|
|
||||||
|
# 导入 studiolibrary
|
||||||
|
import studiolibrary
|
||||||
|
_studiolibrary_module = studiolibrary
|
||||||
|
return _studiolibrary_module
|
||||||
|
|
||||||
|
def version():
|
||||||
|
return __version__
|
||||||
|
|
||||||
|
# 导出所有公共接口
|
||||||
|
__all__ = [
|
||||||
|
'__version__',
|
||||||
|
'version',
|
||||||
|
'show',
|
||||||
|
'main',
|
||||||
]
|
]
|
||||||
|
|
||||||
for _path in _required_paths:
|
|
||||||
if _path not in sys.path:
|
|
||||||
sys.path.insert(0, _path)
|
|
||||||
|
|
||||||
# 从内层 studiolibrary 模块导入所有功能
|
|
||||||
try:
|
|
||||||
from studiolibrary import (
|
|
||||||
__version__,
|
|
||||||
version,
|
|
||||||
config,
|
|
||||||
resource,
|
|
||||||
Library,
|
|
||||||
LibraryItem,
|
|
||||||
main,
|
|
||||||
)
|
|
||||||
|
|
||||||
# 导入工具函数
|
|
||||||
from studiolibrary.utils import *
|
|
||||||
|
|
||||||
# 导出所有公共接口
|
|
||||||
__all__ = [
|
|
||||||
'__version__',
|
|
||||||
'version',
|
|
||||||
'config',
|
|
||||||
'resource',
|
|
||||||
'Library',
|
|
||||||
'LibraryItem',
|
|
||||||
'main',
|
|
||||||
]
|
|
||||||
|
|
||||||
except ImportError as e:
|
|
||||||
import traceback
|
|
||||||
print("Failed to import studiolibrary:")
|
|
||||||
print(traceback.format_exc())
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
def show(*args, **kwargs):
|
def show(*args, **kwargs):
|
||||||
"""
|
"""
|
||||||
@@ -70,8 +62,27 @@ def show(*args, **kwargs):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
LibraryWindow: Studio Library 窗口实例
|
LibraryWindow: Studio Library 窗口实例
|
||||||
|
|
||||||
|
Example:
|
||||||
|
>>> import animation_tools.studiolibrary
|
||||||
|
>>> animation_tools.studiolibrary.show()
|
||||||
"""
|
"""
|
||||||
return main(*args, **kwargs)
|
lib = _ensure_studiolibrary_loaded()
|
||||||
|
return lib.main(*args, **kwargs)
|
||||||
|
|
||||||
|
def main(*args, **kwargs):
|
||||||
|
"""
|
||||||
|
启动 Studio Library 主窗口
|
||||||
|
|
||||||
|
Args:
|
||||||
|
*args: 传递给 main() 的位置参数
|
||||||
|
**kwargs: 传递给 main() 的关键字参数
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
LibraryWindow: Studio Library 窗口实例
|
||||||
|
"""
|
||||||
|
lib = _ensure_studiolibrary_loaded()
|
||||||
|
return lib.main(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def isMaya():
|
def isMaya():
|
||||||
@@ -85,5 +96,5 @@ def isMaya():
|
|||||||
import maya.cmds
|
import maya.cmds
|
||||||
maya.cmds.about(batch=True)
|
maya.cmds.about(batch=True)
|
||||||
return True
|
return True
|
||||||
except ImportError:
|
except (ImportError, AttributeError):
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -23,31 +23,32 @@ def LaunchStudioLibrary():
|
|||||||
# 获取 Studio Library 路径
|
# 获取 Studio Library 路径
|
||||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
# 确保路径在 sys.path 中
|
# 关键:直接将内层 studiolibrary 子目录放到 sys.path 最前面
|
||||||
if current_dir not in sys.path:
|
# 这样 import studiolibrary 会直接找到内层的,避免循环导入
|
||||||
sys.path.insert(0, current_dir)
|
|
||||||
|
|
||||||
# 确保子模块路径也在 sys.path 中
|
|
||||||
studiolibrary_subdir = os.path.join(current_dir, 'studiolibrary')
|
studiolibrary_subdir = os.path.join(current_dir, 'studiolibrary')
|
||||||
if studiolibrary_subdir not in sys.path:
|
|
||||||
sys.path.insert(0, studiolibrary_subdir)
|
|
||||||
|
|
||||||
# 导入 Studio Library
|
# 临时保存并清理 sys.path,避免外层包干扰
|
||||||
try:
|
original_path = sys.path[:]
|
||||||
# 方式1:直接从外层包导入
|
sys.path.insert(0, studiolibrary_subdir)
|
||||||
import studiolibrary
|
|
||||||
except ImportError:
|
# 添加其他必要的路径
|
||||||
# 方式2:从子目录导入
|
for subdir in ['studiolibrarymaya', 'mutils', 'studioqt', 'studiovendor']:
|
||||||
sys.path.insert(0, studiolibrary_subdir)
|
subdir_path = os.path.join(current_dir, subdir)
|
||||||
import studiolibrary
|
if subdir_path not in sys.path:
|
||||||
|
sys.path.insert(0, subdir_path)
|
||||||
|
|
||||||
|
# 导入 Studio Library(现在会找到内层的)
|
||||||
|
import studiolibrary
|
||||||
|
|
||||||
# 打印版本信息
|
# 打印版本信息
|
||||||
print(f"Studio Library version: {studiolibrary.version()}")
|
print("Studio Library version: " + str(studiolibrary.version()))
|
||||||
|
|
||||||
# 检测 Maya 环境
|
# 检测 Maya 环境
|
||||||
if studiolibrary.isMaya():
|
try:
|
||||||
|
import maya.cmds
|
||||||
|
maya.cmds.about(batch=True)
|
||||||
print("Studio Library: Running in Maya environment")
|
print("Studio Library: Running in Maya environment")
|
||||||
else:
|
except (ImportError, AttributeError):
|
||||||
print("Studio Library: Running in standalone mode")
|
print("Studio Library: Running in standalone mode")
|
||||||
|
|
||||||
# 启动主窗口
|
# 启动主窗口
|
||||||
@@ -58,16 +59,16 @@ def LaunchStudioLibrary():
|
|||||||
return window
|
return window
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to launch Studio Library: {e}")
|
print("Failed to launch Studio Library: " + str(e))
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
# 提供详细的调试信息
|
# 提供详细的调试信息
|
||||||
print("\n=== Debug Information ===")
|
print("\n=== Debug Information ===")
|
||||||
print(f"Current directory: {os.path.dirname(os.path.abspath(__file__))}")
|
print("Current directory: " + os.path.dirname(os.path.abspath(__file__)))
|
||||||
print(f"sys.path entries:")
|
print("sys.path entries:")
|
||||||
for i, path in enumerate(sys.path[:10]):
|
for i, path in enumerate(sys.path[:10]):
|
||||||
print(f" [{i}] {path}")
|
print(" [" + str(i) + "] " + path)
|
||||||
print("=========================\n")
|
print("=========================\n")
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user