Skip to main content
Glama

execute_python_script

Run Python scripts within Cinema 4D to access the c4d API for 3D modeling, animation, and scene manipulation tasks directly through code execution.

Instructions

Execute a Python script in Cinema 4D's Python environment.

This is the most reliable tool for non-trivial operations — it gives full access
to the c4d API and avoids wrapper/schema mismatches that can affect other tools.

Args:
    script: Python code to execute in Cinema 4D. Has access to `c4d` and
        `c4d.modules.mograph` modules.

Important usage notes:
    - For animated/MoGraph data, always call doc.ExecutePasses() after SetTime():
        doc.SetTime(c4d.BaseTime(frame, fps))
        doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_NONE)
    - For MoGraph/effector data, iterate frames sequentially (0..N) rather than
      jumping directly to a later frame — sequential stepping produces more
      faithful results.
    - Security restrictions block certain keywords: import os, subprocess, exec(, eval(.
      Keep scripts within the c4d API surface.
    - For heavy operations (dense frame loops, complex MoGraph scenes), split work
      into multiple smaller scripts rather than one large monolith.
    - Use print() to return results — output is captured and returned.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYes

Implementation Reference

  • The handler implementation for the `execute_python_script` tool, which sends a script to Cinema 4D via a socket connection and formats the response.
    async def execute_python_script(script: str, ctx: Context) -> str:
        """
        Execute a Python script in Cinema 4D's Python environment.
    
        This is the most reliable tool for non-trivial operations — it gives full access
        to the c4d API and avoids wrapper/schema mismatches that can affect other tools.
    
        Args:
            script: Python code to execute in Cinema 4D. Has access to `c4d` and
                `c4d.modules.mograph` modules.
    
        Important usage notes:
            - For animated/MoGraph data, always call doc.ExecutePasses() after SetTime():
                doc.SetTime(c4d.BaseTime(frame, fps))
                doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_NONE)
            - For MoGraph/effector data, iterate frames sequentially (0..N) rather than
              jumping directly to a later frame — sequential stepping produces more
              faithful results.
            - Security restrictions block certain keywords: import os, subprocess, exec(, eval(.
              Keep scripts within the c4d API surface.
            - For heavy operations (dense frame loops, complex MoGraph scenes), split work
              into multiple smaller scripts rather than one large monolith.
            - Use print() to return results — output is captured and returned.
        """
        async with c4d_connection_context() as connection:
            if not connection.connected:
                return "❌ Not connected to Cinema 4D"
    
            # Send command to Cinema 4D
            response = send_to_c4d(
                connection, {"command": "execute_python", "script": script}
            )
            return format_c4d_response(response, "execute_python")
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It comprehensively describes critical behavioral traits: security restrictions (blocking certain keywords), performance considerations (splitting heavy operations), output mechanism (using print() to return results), and specific API usage patterns (ExecutePasses after SetTime, sequential frame iteration). This goes well beyond what a basic description would provide.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, args, important usage notes) and every sentence adds value. While comprehensive, it might be slightly verbose for a single-parameter tool, but the information density is high with no wasted text. The front-loaded purpose statement immediately communicates the tool's core function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of executing arbitrary Python code in a specialized environment with no annotations or output schema, the description provides exceptional completeness. It covers purpose, usage guidelines, behavioral constraints, parameter details, security considerations, performance best practices, and output mechanism. For a tool with this level of complexity and zero structured metadata, the description is remarkably thorough.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage for the single parameter, the description fully compensates by providing detailed semantics for the 'script' parameter. It explains what the script should contain ('Python code to execute'), what modules are available ('access to c4d and c4d.modules.mograph'), and provides multiple examples of proper script structure and content throughout the usage notes.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Execute a Python script') and the target environment ('in Cinema 4D's Python environment'), distinguishing it from sibling tools that perform specific operations like 'add_effector' or 'render_frame'. It explicitly mentions this is for 'non-trivial operations' and gives 'full access to the c4d API', which differentiates it from more specialized tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool ('most reliable tool for non-trivial operations') and when to use alternatives ('avoids wrapper/schema mismatches that can affect other tools'). It also includes specific usage notes for different scenarios (animated/MoGraph data, heavy operations), making it clear when this tool is preferred over others.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ttiimmaacc/cinema4d-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server