Skip to main content
Only NOTE files have layer data; other file types do not.
static modifyLayers(NOTEPath: string, page: number, layers: Layer[]): Promise<APIResponse<boolean>>;
Parameters
ParameterTypeDescription
NOTEPathstringNOTE file path
pagenumberPage index (starts from 0)
layersLayer[]Existing layer data array
Returns

Example

import { PluginFileAPI, type Layer } from 'sn-plugin-lib';

/**
 * Example: modify page layer data.
 */
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 call failed');
 }

 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 = 'work layer';
 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 call failed');
 }
 return res.result;
}