hi,
try this code
async function test() {
await require("photoshop").core.executeAsModal(CreateLayerToTop, {
"commandName": "test"
});
}
async function CreateLayerToTop() {
let cl = await app.activeDocument.activeLayers[0];
if (cl.parent != null) {
while (cl.parent != null) {
await require("photoshop").action.batchPlay([
Layer_Add(),
], {
synchronousExecution: false
});
await require("photoshop").action.batchPlay([
Layer_Move_Top(),
], {
synchronousExecution: false
});
cl = await app.activeDocument.activeLayers[0];
}
}else{
await require("photoshop").action.batchPlay([
Layer_Add(),
], {
synchronousExecution: false
});
await require("photoshop").action.batchPlay([
Layer_Move_Top(),
], {
synchronousExecution: false
});
}
function Layer_Add() {
const json = {
"_obj": "make",
"_target": [{
"_ref": "layer"
}],
"_isCommand": true
}
return json;
}
function Layer_Move_Top() {
const json = {
"_obj": "move",
"_target": [{
"_ref": "layer",
"_enum": "ordinal",
"_value": "targetEnum"
}],
"to": {
"_ref": "layer",
"_enum": "ordinal",
"_value": "front"
},
"_isCommand": true
}
return json;
}
}