# From Python inside Rhino

Scripts inside Rhino (Raven's `ravencode script`, Rhino MCP's `run_python`, the Script Editor) call
the same tools as MCP, with JSON in and out:

```python
import clr, json
try:
    clr.AddReference("jifto")
except Exception:
    import System  # not on the search path: use the jifto Rhino has already loaded
    loaded = [a for a in System.AppDomain.CurrentDomain.GetAssemblies() if a.GetName().Name == "jifto"]
    if not loaded:
        raise RuntimeError("jifto is not loaded in this Rhino, or is older than 1.5: tell the person.")
    clr.AddReference(loaded[0].Location)
from jifto.Agents import JiftoAgentApi as jifto

def call(tool, **args):
    reply = json.loads(jifto.Call(tool, json.dumps(args)))
    if reply.get("ok") is False:
        raise RuntimeError(reply["error"] + " " + reply.get("fix", ""))
    return reply

ground = call("jifto_geometry", action="add", items=[{"kind": "box", "min": [-20, -20, -1], "max": [20, 20, 0]}])["created"][0]["id"]
terrain = call("jifto_terrain", action="create", object_id=ground)["terrain"]["id"]
run = call("jifto_run", module="sunlight", wait_seconds=120)
```

- A script holds Rhino's UI thread while it runs. jifto's tools do not need it to let go: every
  change is applied inside the call, and `jifto_job` / `jifto_run` with `wait_seconds` keep Rhino's
  messages flowing while they wait, so the analysis finishes and Rhino stays responsive.
- The person cannot work in Rhino until a script ends. Keep scripts short: one job wait per script.
- Objects you change with RhinoCommon directly (not through `jifto_geometry`) reach jifto when you
  call `jifto_sync` (or any jifto tool that changes something).
- The script and an MCP agent can work on the same Rhino; changes are applied one at a time.
