Hi. Our plugin does something different but maybe you can use these steps. However, there is most likely a more elegant way to do it. We created a library so we can reuse batchplay. You will have to substitute the values where needed and combine the batchplay.
Maybe you want to get active document ID so you can reference it later:
const psApp = require('photoshop').app;
const aDocId = psApp.activeDocument.id;
then Open the image using URL. You might need to create a persistent token to open the file in PS.
Next Select All Pixels On the Active Layer
{
_obj: "set",
_target: [
{
_ref: "channel",
_property: "selection"
}
],
to: {
_enum: "ordinal",
_value: "allEnum"
},
_options: {
dialogOptions: "dontDisplay"
}
}
Next Copy all pixels to clipboard
}
_obj: "copyEvent",
copyHint: "pixels",
_options: {
dialogOptions: "dontDisplay"
}
Close open image
{
_obj: "close",
saving: {
_enum: "yesNo",
_value: "no"
},
documentID: ***INSERTDocumentID***,
_options: {
dialogOptions: "dontDisplay"
}
}
Now select the previously active document by ID ie the doc you want to add new layer
{
_obj: "select",
_target: [
{
_ref: "document",
_id: *INSERTDocumentID*
}
],
documentID: *INSERTDocumentID*,
_options: {
dialogOptions: "dontDisplay"
}
}
Paste Clipboard
{
_obj: "paste",
antiAlias: {
_enum: "antiAliasType",
_value: "antiAliasNone"
},
as: {
_class: "pixel"
},
_options: {
dialogOptions: "dontDisplay"
}
}
Here is rename layer if you need it
{
_obj: "set",
_target: [
{
_ref: "layer",
_enum: "ordinal",
_value: "targetEnum"
}
],
to: {
_obj: "layer",
name: INSERTNewLayerName
},
_options: {
dialogOptions: "dontDisplay"
}
}