This commit is contained in:
2025-11-24 22:26:56 +08:00
parent e4c713035b
commit 719058ff01
8 changed files with 310 additions and 33 deletions

View File

@@ -1619,5 +1619,28 @@ def extraOptions():
cmds.showWindow("Extra_Options")
# 导出主要函数,使其可以从外部调用
__all__ = [
'fk_to_ik',
'ik_to_fk',
'delete_setup',
'documentation',
'extraOptions',
'user_interface',
]
def show():
"""
便捷函数:启动 IK/FK Switcher UI
使用方法:
import animation_tools.ik_fk_switcher as ikfk
ikfk.show()
"""
user_interface()
if __name__ == "__main__":
user_interface()

View File

@@ -25,20 +25,42 @@ Studio Library 2.20.2
## 使用方法
### 在 Python 中启动
### 方式 1使用 launcher推荐
```python
from animation_tools.studiolibrary import launcher
launcher.LaunchStudioLibrary()
```
### 方式 2直接导入
```python
# 需要先添加路径到 sys.path
import sys
import os
studiolibrary_path = r'h:\Workspace\Raw\Tools\Plugins\Maya\2023\scripts\animation_tools\studiolibrary'
if studiolibrary_path not in sys.path:
sys.path.insert(0, studiolibrary_path)
# 然后导入并启动
import studiolibrary
studiolibrary.main()
```
### 方式 3从 animation_tools 导入
```python
# 如果 animation_tools 已在 PYTHONPATH 中
from animation_tools import studiolibrary
studiolibrary.main()
```
### 在 MEL 中启动
```mel
python("from animation_tools.studiolibrary import launcher; launcher.LaunchStudioLibrary()");
```
### 从工具架启动
点击动画工具架上的 **StudioLib** 按钮即可启动。
@@ -62,9 +84,15 @@ studiolibrary.main()
## 🔧 版本兼容性
### 支持的 Maya 版本
- **Maya 2017+** - 支持所有现代版本的 Maya
- **Maya 2017-2024** - 使用 PySide2
- **Maya 2025+** - 使用 PySide6
- **自动适配** - 运行时自动检测 Maya 环境和 Qt 版本
### Maya 2025 特别说明
- ✅ 已创建外层 `__init__.py` 文件,解决模块导入问题
- ✅ 自动检测并使用 PySide6
- ✅ 完全兼容新版本的 Python 3.11
### Qt 兼容性
Studio Library 使用 `Qt.py` 兼容层,支持多种 Qt 绑定:
- **PySide6** - Maya 2025+ (优先)

View File

@@ -0,0 +1,89 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Studio Library Wrapper Module
用于简化 Studio Library 的导入和使用
支持 Maya 2017-2026+ 所有版本
"""
import sys
import os
# 获取当前目录
_current_dir = os.path.dirname(os.path.abspath(__file__))
# 确保所有子模块路径都在 sys.path 中
_required_paths = [
_current_dir,
os.path.join(_current_dir, 'studiolibrary'),
os.path.join(_current_dir, 'studiolibrarymaya'),
os.path.join(_current_dir, 'mutils'),
os.path.join(_current_dir, 'studioqt'),
os.path.join(_current_dir, 'studiovendor'),
]
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):
"""
便捷函数:启动 Studio Library
Args:
*args: 传递给 main() 的位置参数
**kwargs: 传递给 main() 的关键字参数
Returns:
LibraryWindow: Studio Library 窗口实例
"""
return main(*args, **kwargs)
def isMaya():
"""
检查是否在 Maya 环境中运行
Returns:
bool: 如果在 Maya 中返回 True否则返回 False
"""
try:
import maya.cmds
maya.cmds.about(batch=True)
return True
except ImportError:
return False

View File

@@ -4,7 +4,7 @@
"""
Studio Library Launcher
用于从工具架快速启动 Studio Library
支持所有 Maya 版本
支持所有 Maya 版本2017-2026+
"""
import sys
@@ -15,6 +15,9 @@ def LaunchStudioLibrary():
"""
启动 Studio Library 主界面
自动检测 Maya 版本和 Qt 绑定
Returns:
LibraryWindow: Studio Library 窗口实例,失败时返回 None
"""
try:
# 获取 Studio Library 路径
@@ -24,17 +27,28 @@ def LaunchStudioLibrary():
if current_dir not in sys.path:
sys.path.insert(0, current_dir)
# 导入并启动 Studio Library
import studiolibrary
# 确保子模块路径也在 sys.path 中
studiolibrary_subdir = os.path.join(current_dir, 'studiolibrary')
if studiolibrary_subdir not in sys.path:
sys.path.insert(0, studiolibrary_subdir)
# 导入 Studio Library
try:
# 方式1直接从外层包导入
import studiolibrary
except ImportError:
# 方式2从子目录导入
sys.path.insert(0, studiolibrary_subdir)
import studiolibrary
# 打印版本信息
print(f"Studio Library version: {studiolibrary.version()}")
# 检测 Maya 环境
if studiolibrary.isMaya():
print("Running in Maya environment")
print("Studio Library: Running in Maya environment")
else:
print("Running in standalone mode")
print("Studio Library: Running in standalone mode")
# 启动主窗口
window = studiolibrary.main()
@@ -47,6 +61,15 @@ def LaunchStudioLibrary():
print(f"Failed to launch Studio Library: {e}")
import traceback
traceback.print_exc()
# 提供详细的调试信息
print("\n=== Debug Information ===")
print(f"Current directory: {os.path.dirname(os.path.abspath(__file__))}")
print(f"sys.path entries:")
for i, path in enumerate(sys.path[:10]):
print(f" [{i}] {path}")
print("=========================\n")
return None

View File

@@ -0,0 +1,71 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
IK/FK Switcher 测试脚本
在 Maya 中运行此脚本来测试模块是否正常工作
"""
def test_ik_fk_switcher():
"""测试 ik_fk_switcher 模块的导入和函数"""
print("=" * 60)
print("IK/FK Switcher 测试")
print("=" * 60)
try:
# 测试导入
print("\n[1/5] 测试导入模块...")
import animation_tools.ik_fk_switcher as ikfk
print("✓ 成功导入 ik_fk_switcher")
# 测试 __all__ 导出
print("\n[2/5] 检查 __all__ 导出列表...")
if hasattr(ikfk, '__all__'):
print(f"✓ __all__ = {ikfk.__all__}")
else:
print("✗ 没有找到 __all__")
# 测试主要函数
print("\n[3/5] 检查主要函数...")
functions = ['fk_to_ik', 'ik_to_fk', 'delete_setup', 'documentation', 'extraOptions', 'user_interface', 'show']
for func_name in functions:
if hasattr(ikfk, func_name):
func = getattr(ikfk, func_name)
print(f"{func_name}: {type(func)}")
else:
print(f"{func_name}: 未找到")
# 测试 show() 函数
print("\n[4/5] 测试 show() 函数...")
if hasattr(ikfk, 'show') and callable(ikfk.show):
print("✓ show() 函数可调用")
print(f" 文档: {ikfk.show.__doc__}")
else:
print("✗ show() 函数不可用")
# 测试 dir()
print("\n[5/5] 列出所有可用属性...")
all_attrs = [attr for attr in dir(ikfk) if not attr.startswith('_')]
print(f"✓ 共有 {len(all_attrs)} 个公共属性/函数")
print(f" 主要函数: {[attr for attr in all_attrs if callable(getattr(ikfk, attr))][:10]}")
print("\n" + "=" * 60)
print("所有测试通过!")
print("=" * 60)
print("\n使用方法:")
print(" import animation_tools.ik_fk_switcher as ikfk")
print(" ikfk.show() # 启动 UI")
print("=" * 60)
return True
except Exception as e:
print(f"\n✗ 测试失败: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
# 在 Maya 中运行
test_ik_fk_switcher()