• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

“Layer Via Copy” is not currently available. Error From UXP Scripting

New Here ,
Apr 10, 2023 Apr 10, 2023

Copy link to clipboard

Copied

Photoshop v24.1.0

App Version 24.1.0

UXP Version 6.4.0

 

 

Goal:

I am writing a plugin and from the UI I want to click a button and have that trigger a series of functions to do the following.

 

1) Select a layer : "mainimage"

2) Create a selection on that layer

3) Copy that selection to a newlayer 

4) Rename that new layer to : temp_image

5) Export that temp_image layer with a randomized name

 

Method 01:

1) Create an 'action' of the steps listed above

2) Play that action in response to a button trigger from the UI

 

Method 02: 

1) Use a plugin called 'Alchemist" to record the UI actions and convert them into batch commands

2) Run those batch command in sequence in response to a button trigger from the UI

 

Challenge :

 

The entire operation will run successfully the first time. 

Any attempt via the plugin made after the first one will Fail with the following error :

The command “Layer Via Copy” is not currently available.

Running the actions through the UI will work every single time with no error.

 

What I think is happening:

When i execute the command the first time it somehow locks the "copy via layer" command. Each susbsequent call from the plugin fails.  

 

====================== METHOD 01 ==============

 

document.querySelector("#btnNewInstance").onclick = handleNewInstanceBtn;

 

function handleNewInstanceBtn(){

        createTempImageLayer()
        deselectAllLayers()
}

 

 

async function createTempImageLayer() {

const batchCommands = {
_obj: "play",
_target: [
{
_ref: "action",
_name: "Create MainImage"
},
{
_ref: "actionSet",
_name: "Default Actions"
}
],
_options: {
dialogOptions: "dontDisplay"
}
}
console.log("BatchCommands : createTempImageLayer")

return await require("photoshop").core.executeAsModal(async () => {
await require('photoshop').action.batchPlay([batchCommands], { });
}, { commandName: "Make New Text Layer" });
}

 

async function deselectAllLayers() {

const batchCommands = {
_obj: "set",
_target: [
{
_ref: "channel",
_property: "selection"
}
],
to: {
_enum: "ordinal",
_value: "none"
},
_options: {
dialogOptions: "dontDisplay"
}
}

console.log("BatchCommands : deselectAllLayers")

return await require("photoshop").core.executeAsModal(async () => {
await require('photoshop').action.batchPlay([batchCommands], { });
}, { commandName: "Make New Text Layer" });
}

 

====================== METHOD 02 ==============

 

async function makeSelection() {

const batchCommands = {
_obj: "set",
_target: [
{
_ref: "channel",
_property: "selection"
}
],
to: {
_obj: "rectangle",
top: {
_unit: "distanceUnit",
_value: 410.88
},
left: {
_unit: "distanceUnit",
_value: 0
},
bottom: {
_unit: "distanceUnit",
_value: 1296
},
right: {
_unit: "distanceUnit",
_value: 1031.52
}
},
_options: {
dialogOptions: "dontDisplay"
}
}


const batchCommands2 = {
_obj: "copyToLayer",
_options: {
dialogOptions: "dontDisplay"
}
}

 

console.log("batchCommands : makeSelection")

return await require("photoshop").core.executeAsModal(async () => {
await require('photoshop').action.batchPlay([batchCommands,batchCommands2], { synchronousExecution: true,
modalBehavior: "fail"});
}, { commandName: "Make New Text Layer" });
}

 

 

 


async function copyToNewLayer() {

const batchCommands = {
_obj: "copyToLayer",
_options: {
dialogOptions: "dontDisplay"
}
}
console.log("BatchCommands : copyToLayer")

return await require("photoshop").core.executeAsModal(async () => {
await require('photoshop').action.batchPlay([batchCommands], { });
}, { commandName: "Make New Text Layer" });
}

 

 

 

Any advice would be useful and very well recieved ...!!!

 

Thanks

TOPICS
Actions and scripting , macOS , SDK

Views

404

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation
Adobe