Hi all, apologies as I am very new to JavaScript, this is probably a very basic question. Sorry if this is not the right place to ask this, please let me know. Any help would be appreciated.
I have an action that does a few steps on the active file, opens a mockup template PSD and then continues action steps on the template file. I have learned that the UXP will not open a file unless it is in the plugin folder, so I grabbed some code from another post here to help open the file from the plugin folder. Once the file is open, how do I have the action continue steps on the newly opened template? Right now the code is trying to perform all of these action steps on the original design file, and then opening the template afterwards.
Here is my Frankenstein attempt:
async function createComp () {
{
let batchPlay = require("photoshop").action.batchPlay;
let result = await batchPlay(
[
//First part of action to run on original active file
// Make layer
{"_obj":"make","_target":[{"_ref":"layer"}],"layerID":370},
// Flatten Image
{"_obj":"flattenImage"},
// Convert Mode
{"_obj":"convertMode","to":{"_class":"RGBColorMode"}},
// Image Size
{"_obj":"imageSize","height":{"_unit":"pixelsUnit","_value":400.0},"interfaceIconFrameDimmed":{"_enum":"interpolationType","_value":"automaticInterpolation"},"resolution":{"_unit":"densityUnit","_value":72.0},"width":{"_unit":"pixelsUnit","_value":1400.0}},
// Set Selection
{"_obj":"set","_target":[{"_property":"selection","_ref":"channel"}],"to":{"_enum":"ordinal","_value":"allEnum"}},
// Copy
{"_obj":"copyEvent","copyHint":"pixels"},
// Set Selection
{"_obj":"set","_target":[{"_property":"selection","_ref":"channel"}],"to":{"_enum":"ordinal","_value":"none"}},
],{
synchronousExecution: false,
modalBehavior: "wait"
})
//Code to open template from plugins folder
const { app, core } = require("photoshop");
const fs = require("uxp").storage.localFileSystem;
async function openDocument() {
let pluginFolder = await fs.getPluginFolder();
let theTemplate = await pluginFolder.getEntry("comp-PSDs/DBB_400x1400.psd");
await app.open(theTemplate);
}
async function main() {
await core.executeAsModal(openDocument);
}
try {
main();
} catch (error) {
console.error(error);
console.trace(error);
}
{
let batchPlay = require("photoshop").action.batchPlay;
let result = await batchPlay(
[
//Second part of action to run within template file
// Select layer “1400x400_DigitalBulletin_Art”
{"_obj":"select","_target":[{"_name":"1400x400_DigitalBulletin_Art","_ref":"layer"}],"layerID":[525],"makeVisible":false},
// Edit Contents
{"_obj":"placedLayerEditContents"},
// Paste
{"_obj":"paste","antiAlias":{"_enum":"antiAliasType","_value":"antiAliasNone"},"as":{"_class":"pixel"},"inPlace":true},
// Hide layer “Template - Turn OFF”
{"_obj":"hide","null":[{"_name":"Template - Turn OFF","_ref":"layer"}]},
// Save
{"_obj":"save"},
// Close
],{
synchronousExecution: false,
modalBehavior: "wait"
});
}
};
}
document
.getElementById("btnAutoComp")
.addEventListener("click", () =>
require("photoshop").core.executeAsModal(createComp));