118 lines
2.9 KiB
Python
118 lines
2.9 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
Studio Library Wrapper Module
|
|
Simplify Studio Library import and usage
|
|
Support Maya 2017-2026+ all versions
|
|
|
|
Usage:
|
|
import animation_tools.studiolibrary
|
|
animation_tools.studiolibrary.show()
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
# Get current directory
|
|
_current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
# Global variable to store imported module
|
|
_studiolibrary_module = None
|
|
__version__ = "2.20.2"
|
|
|
|
def _ensure_studiolibrary_loaded():
|
|
"""Ensure studiolibrary module is loaded"""
|
|
global _studiolibrary_module
|
|
|
|
if _studiolibrary_module is not None:
|
|
return _studiolibrary_module
|
|
|
|
# Add all necessary paths
|
|
_inner_studiolibrary = os.path.join(_current_dir, 'studiolibrary')
|
|
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)
|
|
|
|
# Import from inner studiolibrary by temporarily manipulating sys.path
|
|
# Remove current directory to avoid circular import
|
|
_saved_path = sys.path[:]
|
|
if _current_dir in sys.path:
|
|
sys.path.remove(_current_dir)
|
|
|
|
# Add inner studiolibrary to the front
|
|
if _inner_studiolibrary not in sys.path:
|
|
sys.path.insert(0, _inner_studiolibrary)
|
|
|
|
try:
|
|
import studiolibrary
|
|
_studiolibrary_module = studiolibrary
|
|
finally:
|
|
# Restore sys.path
|
|
sys.path = _saved_path
|
|
# But keep the inner studiolibrary path
|
|
if _inner_studiolibrary not in sys.path:
|
|
sys.path.insert(0, _inner_studiolibrary)
|
|
|
|
return _studiolibrary_module
|
|
|
|
def version():
|
|
return __version__
|
|
|
|
# Export all public interfaces
|
|
__all__ = [
|
|
'__version__',
|
|
'version',
|
|
'show',
|
|
'main',
|
|
]
|
|
|
|
|
|
def show(*args, **kwargs):
|
|
"""
|
|
Convenience function: Launch Studio Library
|
|
|
|
Args:
|
|
*args: Positional arguments passed to main()
|
|
**kwargs: Keyword arguments passed to main()
|
|
|
|
Returns:
|
|
LibraryWindow: Studio Library window instance
|
|
|
|
Example:
|
|
>>> import animation_tools.studiolibrary
|
|
>>> animation_tools.studiolibrary.show()
|
|
"""
|
|
lib = _ensure_studiolibrary_loaded()
|
|
return lib.main(*args, **kwargs)
|
|
|
|
def main(*args, **kwargs):
|
|
"""
|
|
Launch Studio Library main window
|
|
|
|
Args:
|
|
*args: Positional arguments passed to main()
|
|
**kwargs: Keyword arguments passed to main()
|
|
|
|
Returns:
|
|
LibraryWindow: Studio Library window instance
|
|
"""
|
|
lib = _ensure_studiolibrary_loaded()
|
|
return lib.main(*args, **kwargs)
|
|
|
|
|
|
def isMaya():
|
|
"""
|
|
Check if running in Maya environment
|
|
|
|
Returns:
|
|
bool: True if in Maya, False otherwise
|
|
"""
|
|
try:
|
|
import maya.cmds
|
|
maya.cmds.about(batch=True)
|
|
return True
|
|
except (ImportError, AttributeError):
|
|
return False
|