53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
Maya MCP Auto-Load Script
|
|
This script automatically loads the MCP server when Maya starts.
|
|
|
|
Version: 1.0.0
|
|
Author: Jeffrey Tsai
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import maya.utils as utils
|
|
import logging
|
|
import traceback
|
|
|
|
# Configure logging
|
|
logging.basicConfig(level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
logger = logging.getLogger("MayaMCP.AutoLoad")
|
|
|
|
def initialize_mcp():
|
|
"""Initialize MCP server and menu"""
|
|
try:
|
|
# Get the directory containing this file
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
# Add the current directory to the Python path if not already there
|
|
if current_dir not in sys.path:
|
|
sys.path.append(current_dir)
|
|
logger.info(f"Added {current_dir} to Python path")
|
|
|
|
# Import MCP loader
|
|
try:
|
|
from loader import auto_load
|
|
|
|
# Auto-load MCP
|
|
success = auto_load()
|
|
if success:
|
|
logger.info("MCP auto-load successful")
|
|
else:
|
|
logger.error("MCP auto-load failed")
|
|
except Exception as e:
|
|
logger.error(f"Error importing MCP loader: {e}")
|
|
logger.error(traceback.format_exc())
|
|
except Exception as e:
|
|
logger.error(f"Error initializing MCP: {e}")
|
|
logger.error(traceback.format_exc())
|
|
|
|
# Use Maya's deferred execution mechanism to ensure Maya is fully started
|
|
utils.executeDeferred(initialize_mcp)
|