create_command.py•3.3 kB
#!/usr/bin/env python
"""
Create Command File for After Effects MCP
This script directly creates a command file in the exact location that After Effects is checking.
"""
import os
import json
import time
import shutil
from pathlib import Path
# Command file paths to try
COMMAND_PATHS = [
"C:/ae_temp/command.json",
"C:\\ae_temp\\command.json",
"/c/ae_temp/command.json",
"C:/ae_temp/command.json"
]
def ensure_directory_exists(dir_path):
"""Ensure the directory exists"""
try:
Path(dir_path).mkdir(parents=True, exist_ok=True)
print(f"✅ Directory ready: {dir_path}")
return True
except Exception as e:
print(f"❌ Error creating directory: {e}")
return False
def create_command_file(path, command_data):
"""Create a command file at the specified path"""
try:
# Ensure directory exists
dir_path = os.path.dirname(path)
if not ensure_directory_exists(dir_path):
return False
# Write to a temporary file first
temp_path = f"{path}.tmp"
with open(temp_path, 'w') as f:
json.dump(command_data, f, indent=2)
# Move to final location (atomic operation)
shutil.move(temp_path, path)
print(f"✅ Command file created at: {path}")
return True
except Exception as e:
print(f"❌ Error creating command file: {e}")
return False
def create_text_layer_command():
"""Create a command to add a text layer"""
return {
"action": "create_text_layer",
"params": {
"text": "Direct Python Test",
"fontSize": 72,
"color": "#00FF00"
}
}
def main():
"""Main function"""
print("=" * 60)
print("Create Command File for After Effects MCP")
print("=" * 60)
# Create a text layer command
command = create_text_layer_command()
print(f"Command data: {json.dumps(command, indent=2)}")
# Try all paths
success = False
for path in COMMAND_PATHS:
print(f"\nTrying path: {path}")
if create_command_file(path, command):
success = True
print(f"Successfully created command file at: {path}")
print("Now click 'Check for Command' in After Effects")
break
if not success:
print("\n❌ Failed to create command file at any path")
print("Please check directory permissions and try again")
print("\nWaiting for result file...")
result_path = "C:/ae_temp/result.json"
start_time = time.time()
while not os.path.exists(result_path):
time.sleep(0.5)
elapsed = time.time() - start_time
if elapsed > 30:
print("Timeout: No result file found after 30 seconds")
break
if int(elapsed) % 5 == 0 and elapsed > 0:
print(f"Still waiting... ({int(elapsed)}s)")
if os.path.exists(result_path):
print("\n✅ Result file found!")
try:
with open(result_path, 'r') as f:
result = json.load(f)
print(f"Result: {json.dumps(result, indent=2)}")
except Exception as e:
print(f"Error reading result file: {e}")
if __name__ == "__main__":
main()