execute_blender_code
Execute Python code directly within Blender to automate 3D modeling tasks, manipulate IFC building models, and control Blender's functionality programmatically.
Instructions
Execute arbitrary Python code in Blender.
Parameters:
- code: The Python code to execute
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes |
Implementation Reference
- tools.py:242-259 (handler)The primary handler implementation for the 'execute_blender_code' MCP tool. This function is decorated with @mcp.tool(), receives the code parameter, establishes a connection to Blender, sends an 'execute_code' command with the provided code, and returns the execution result or an error message.@mcp.tool() def execute_blender_code(ctx: Context, code: str) -> str: """ Execute arbitrary Python code in Blender. Parameters: - code: The Python code to execute """ try: # Get the global connection blender = get_blender_connection() result = blender.send_command("execute_code", {"code": code}) return f"Code executed successfully: {result.get('result', '')}" except Exception as e: logger.error(f"Error executing code: {str(e)}") return f"Error executing code: {str(e)}"