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

# modifyLayers

> 修改页面图层数据（不存在的图层不会修改）。

<Note>
  只有笔记文件才有图层数据，其他文件没有图层数据。
</Note>

<Note>
  主图层和背景图层不支持修改图层名称。即使传入新的 `name`，也不会生效，界面中仍会显示默认名称。
</Note>

```ts wrap theme={null}
static modifyLayers(notePath: string, page: number, layers: Layer[]): Promise<APIResponse<boolean>>;
```

**参数**

| 参数         | 类型                                                          | 说明                                |
| ---------- | ----------------------------------------------------------- | --------------------------------- |
| `notePath` | `string`                                                    | 笔记文件路径                            |
| `page`     | `number`                                                    | 页面索引（从 0 开始）                      |
| `layers`   | [`Layer[]`](/zh/api-reference/supernote-plugin/types/layer) | 已存在的图层数据数组。主图层和背景图层的 `name` 不支持修改 |

**返回**

* [`APIResponse<boolean>`](/zh/api-reference/supernote-plugin/types/api-response)：
  `result === true` 表示修改成功

## 示例

```ts wrap theme={null}
import { PluginFileAPI, type Layer } from 'sn-plugin-lib';

/**
 * 修改页面图层数据的示例。
 */
export async function exampleModifyLayers() {
  const notePath = '/storage/emulated/0/Note/demo.note';
  const page = 0;

  const listRes = await PluginFileAPI.getLayers(notePath, page);
  if (!listRes.success) {
    throw new Error(listRes.error?.message ?? 'getLayers 调用失败');
  }

  const layers = (listRes.result ?? []) as Layer[];
  const customs = layers.filter((l) => l.layerId >= 1 && l.layerId <= 3);
  const custom = customs[0];
  if (custom) {
    custom.name = '工作图层';
    custom.isVisible = true;
    custom.isCurrentLayer = true;
  }
  layers.forEach((l) => {
    if (l !== custom) {
      l.isCurrentLayer = false;
    }
  });
  const res = await PluginFileAPI.modifyLayers(notePath, page, layers);
  if (!res.success) {
    throw new Error(res.error?.message ?? 'modifyLayers 调用失败');
  }
  return res.result;
}
```
