execute_blender_code
Execute Python code directly within Blender to automate 3D modeling tasks, control materials, and manage scenes through programmatic commands.
Instructions
Execute arbitrary Python code in Blender. Make sure to do it step-by-step by breaking it into smaller chunks.
Parameters:
code: The Python code to execute
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes |
Implementation Reference
- src/blender_mcp/server.py:318-334 (handler)The handler function for the 'execute_blender_code' tool. It uses the global Blender connection to send the provided Python code to Blender for execution via the 'execute_code' command. Includes input validation via type hints and docstring, and error handling.@mcp.tool() def execute_blender_code(ctx: Context, code: str) -> str: """ Execute arbitrary Python code in Blender. Make sure to do it step-by-step by breaking it into smaller chunks. 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)}"