> ## Documentation Index
> Fetch the complete documentation index at: https://www.nexrender.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Scripting overview

> Run your own ExtendScript code inside the After Effects project before a job renders, for changes that functions and data assets can't express

A `script` asset runs your own ExtendScript code inside the job's After Effects project, right before the render starts. Use it when a change needs logic: loops, conditions, reading data files, or restructuring compositions.

## When to use a script

Reach for the simplest asset type that does the job. A script is the most flexible option, and also the one you have to maintain.

| You want to | Use |
| - | - |
| Replace text, images, video, or audio in a layer | [`text`, `image`, `video`, `audio`](https://www.nexrender.com/docs/cloud/jobs/rendering_basics#supported-asset-types) assets |
| Set one property or expression on a layer | A [`data`](https://www.nexrender.com/docs/cloud/jobs/rendering_basics#supported-asset-types) asset |
| Style text, change layer timing, hide or remove layers | A [function](https://www.nexrender.com/docs/cloud/jobs/functions/nx-text-params-set.md) |
| Anything that needs logic, loops, files, or several steps | A `script` asset |

## Before you start

* **Scripting is turned on per team.** If your team doesn't have it, the API rejects any job with a `script` asset with `403` and the error code `SCRIPTING_DISABLED`. Contact [support@nexrender.com](mailto:support@nexrender.com) to get it turned on.
* **Scripts are ExtendScript.** That's the JavaScript dialect After Effects uses for scripting, based on ECMAScript 3. Use `var` and `function`. `let`, arrow functions, and template literals don't work. Nexrender adds `JSON.parse`, `JSON.stringify`, and the array methods `forEach`, `filter`, and `indexOf`, which plain ExtendScript lacks.
* **Scripts run in a sandbox by default.** They can use the After Effects scripting API and files in the job's folder, but not the rest of the machine. See [Sandbox and limits](https://www.nexrender.com/docs/cloud/scripting/sandbox.md).

## Your first script

Host the script anywhere the render node can download it, and reference it from the job:

```json Job payload theme={null}
{
  "template": {
    "id": "YOUR_TEMPLATE_ID",
    "composition": "main"
  },
  "assets": [
    {
      "type": "script",
      "src": "https://example.com/scripts/set-title.jsx",
      "parameters": [
        { "key": "title", "value": "Hello from a script" }
      ]
    }
  ]
}
```

```javascript set-title.jsx theme={null}
var title = NX.get("title") || "Default title";

nexrender.selectLayersByName("main", "Title", function (layer) {
    layer.property("Source Text").setValue(title);
});

nexrender.log("Title set to: " + title);
```

`NX.get("title")` reads a value from the job's `parameters`, and `nexrender.selectLayersByName` finds the layer. [Script assets and parameters](https://www.nexrender.com/docs/cloud/scripting/script-assets.md) and [Helper functions](https://www.nexrender.com/docs/cloud/scripting/helpers.md) cover both in detail.

`src` accepts:

* A public `https://` URL. Google Drive and Dropbox share links work too: Nexrender converts them to direct downloads.
* An inline `data:` URL, for short scripts or quick tests: `data:text/javascript;base64,` followed by the script encoded in Base64.

## How a job runs your script

**1. Download**

Nexrender downloads the template and every asset into a folder for the job.

**2. Assemble**

It builds one After Effects script from your assets, in the order you list them in `assets`. Footage replacements, `text` and `data` assets, functions, and scripts all apply in that order, so a script sees every change made by the assets above it.

**3. Run**

After Effects opens the project and runs the assembled script, then saves the project.

**4. Render**

After Effects renders the job's composition.

If a script throws an error, the job stops before rendering and fails. Start your own error messages with `nexrender:` to make them the job's error word for word. See [Stop the job with a clear error](https://www.nexrender.com/docs/cloud/scripting/examples.md#stop-the-job-with-a-clear-error).

## See what your script did

Lines your script writes with `nexrender.log` go into the job's render log, prefixed with `NX:`. Read the log with `GET /jobs/{id}/logs`, which returns it as plain text, or with the CLI:

```bash theme={null}
nexrender job logs JOB_ID
```

```text Render log (excerpt) theme={null}
NX: Title set to: Hello from a script
```

## Next steps

> [card] [Script assets and parameters](https://www.nexrender.com/docs/cloud/scripting/script-assets.md)
>
> Every field of a script asset, and how to pass values into your script

> [card] [Helper functions](https://www.nexrender.com/docs/cloud/scripting/helpers.md)
>
> The `nexrender` object: find compositions and layers, replace footage, log

> [card] [Examples](https://www.nexrender.com/docs/cloud/scripting/examples.md)
>
> Tested scripts for common tasks

> [card] [Sandbox and limits](https://www.nexrender.com/docs/cloud/scripting/sandbox.md)
>
> What scripts can do on Nexrender Cloud, and the limits that apply


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.