<!-- TE10 Studio documentation: /docs/app/scripting-in-app -->
# Python console and scripts

TE10 Studio can be driven from Python. The same [scripting API](/docs/api/) works in three places:

| Where | How | `prj` is |
|---|---|---|
| **Python Console** (Home tab › Scripting, or **Tools › Python Console**) | Type a line, press <kbd>Enter</kbd> | The project open in the app |
| **Run Script...** (Home tab, or **Tools › Run Script...**) | Pick a `.py` file | The project open in the app |
| A terminal: `te10 run script.py` | Without the app's window | Whatever the script opens or creates |

## The Python Console

![The Python Console at the bottom of the window](/docs/img/app/main-python-console.webp)

In the console:

- `prj` is the open project (a `te10_studio.api.Project`), `em` is the API module and `app` the main
  window.
- Every change goes through the app's undo: <kbd>Ctrl</kbd>+<kbd>Z</kbd> undoes a scripted change too,
  and the view, tree and Properties update.
- `help(prj.modeler)` lists what an object can do.

```python
prj.variables["w"] = "3mm"
trace = prj.modeler.box("Trace", size=("w", 20, 0.035), origin=("-w/2", 0, 1.6), material="copper")
prj.mesh.length_on("0.5mm", objects=[trace])
print(prj.validate())        # [] when the model is ready to solve
```

## Run Script

**Run Script...** runs a whole file against the open project, the same way. Use it for repeated set-up
work: building a parametric part, assigning ports to many traces, exporting results of several setups.

## Macros

**Tools › Macros** holds the built-in [RF tools](/docs/app/rf-tools): calculators, port wizards and
builders. Each is also a Python function (see [RF tools in the API](/docs/api/rftools-materials)).

## Learn the API

Start with the [Scripting API quick start](/docs/api/quickstart). The
[examples](/docs/api/examples) cover waveguides, microstrip, sweeps, eigenmodes, optimisation and
cluster jobs.
