> For the complete documentation index, see [llms.txt](https://stage-precision.gitbook.io/grid/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stage-precision.gitbook.io/grid/scripting/expressions.md).

# Expressions

### Expression Control Mode

A Parameter can be switched from **Manual** control to **Expression** control.

<div align="left"><figure><img src="/files/al7wJh8104SMFj08xaMQ" alt="" width="357"><figcaption></figcaption></figure></div>

When Expression control is enabled, the Parameter value is calculated from the configured expression instead of being entered manually.

For example:

```python
sp.Camera1.camera.camera.focusDistance.value * 3
```

If this expression is assigned to another Camera Parameter, its value will be three times the current Focus Distance.

<div align="left"><figure><img src="/files/yrpFONvmdk2OFh3XcrhO" alt="" width="356"><figcaption></figcaption></figure></div>

Expressions are evaluated reactively. When a referenced Parameter changes, the expression is evaluated again and the resulting value is written to the Parameter.

### Referencing Parameters

Any accessible Parameter can be referenced through its expression address.

For example:

```python
sp.Camera1.camera.camera.focusDistance.value
```

Expression addresses can be copied directly from the Inspector using:

**Secondary-click → Copy Expression Address**

<div align="left"><figure><img src="/files/lLnC5OKo3hHqu8CKYljZ" alt="" width="158"><figcaption></figcaption></figure></div>

This avoids having to manually construct longer Parameter paths.

### Calculating Values

Standard Python-style operators can be used inside an expression.

For example:

```python
sp.Camera1.camera.camera.focusDistance.value * 3
```

Multiple values can also be combined:

```python
sp.Camera1.coordinates.position.value[0] + 2
```

or compared:

```python
sp.Camera1.camera.camera.focusDistance.value > 5
```

The result of the expression is used as the new value of the Parameter.

### Type Conversion

Python-style functions can be used to convert or modify values inside an expression.

For example:

```python
int(sp.Camera1.camera.camera.focusDistance.value) * 3
```

Other functions available in the scripting environment can be used in the same way, provided the complete expression can be written on a single line.

### Creating Structured Values

Expressions can also be used to create values containing multiple elements.

For example, values from an existing Vector Parameter can be accessed individually by index:

```python
[
    sp.Tracker1.coordinates.position.value[0],
    sp.Tracker1.coordinates.position.value[1],
    sp.Tracker1.coordinates.position.value[2]
]
```

### Expression Limitations

Expressions use Python-style syntax, but they are intentionally limited to a **single expression**.

They are designed for reactive Parameter relationships and simple calculations rather than multi-step processing logic.

For example, this is suitable for an Expression:

```python
sp.Camera1.camera.camera.focusDistance.value * 3
```

More complex logic involving multiple statements, callbacks or larger data-processing tasks should instead be implemented using one of Grid Studio's scripting locations such as a **Project Script**, **Workflow Script Action** or **Script Modifier**.

{% hint style="info" %}
An Expression continuously controls its Parameter. If the referenced data changes, the expression is evaluated again and the Parameter value is updated.
{% endhint %}

### Expressions and Other Control Modes

Expression is one of the available Parameter Control Modes in Grid Studio.

Other Control Modes, such as **Manual**, **Variable** and **Target**, provide different ways to control where a Parameter receives its value from.

See the **Parameter Control Modes** documentation for a detailed comparison of the available modes.
