Total noob help required

Hey there.

Im a german Photographer with a bit love for nerd stuff and need to get a Photoshot-Plugin running
wich is doing actually only one small thing but saves me in my workflow a lot of time.
So it would be so nice if someone could help me a bit with probably super basic stuff.
Google is not really helping, probably i even search the wrong things.

App Version 23.3.2
UXP Version 6.0.2

My biggest problem is how to call a function with a variable. I would like to call the function just one time it should paste the pictures in “normal”-mode and the other time in “screen”-mode. So i would like to send a variable as a switch.

By Button code is this.

<sp-action-button id="btn_dropin_normal" class="button_new">Drop-In normal</sp-action-button>
<sp-action-button id="btn_dropin_screen" class="button_new">Drop-In screen</sp-action-button>

and i call the funcion that way

////////////////////////////// LAYER PICTURES ////////////////////////////////////////
function layer_pictures_caller() {
    try {
    catch(e) {
        if (e.number == 9) {
            alert("executeAsModal was rejected (some other plugin is currently inside a modal scope)")
        } else {
            // This case is hit if the targetFunction throws an exception

async function layer_pictures(){
    const offeneDocs = app.documents.length;

    if (offeneDocs > 1){
        if (app.activeDocument == app.documents[0]){
            alert("Dies ist ihre Kompositionsdatei! Bitte zu kopierende Datei auswählen")
        } else {
            var layer = app.activeDocument.layers[0]
            var targetdoc = app.documents[0]
            var closelater = app.activeDocument
            var closelatername =

            const copyLayer = await layer.duplicate(targetdoc)
            app.activeDocument.layers[0].name = closelatername
    } else {
        alert("Es muss mindestens die Kompositionsdatei plus eine zu kopierende Datei offen sein!")


document.getElementById("btn_dropin_normal").addEventListener("click", layer_pictures_caller);
document.getElementById("btn_dropin_screen").addEventListener("click", layer_pictures_caller);

I would be verry happy if someone could help me out.
Be aware im a Noob and already happy i came that far! :slight_smile:

I’d give each button a second property such as name or a data-attribute, and for its value use the string value of the variable you want to pass (in you case either “normal” or “screen”).
Then in your event listener you can grab that property value and pass down to your function with no need for any IF or switch statements.

You could also directly call those functions with the necessary variable:

async function layer_pictures(mode){...}

function layer_pictures_caller(mode) {
    try {
        require('photoshop').core.executeAsModal(() => layer_pictures(mode));

document.getElementById("btn_dropin_normal").addEventListener("click", () => layer_pictures_caller("normal"));
document.getElementById("btn_dropin_screen").addEventListener("click", () => layer_pictures_caller("screen"));

If you want to unsubscribe from that eventListener at a later point you’d have to move those inline handlers to a variable like

const handleNormalDropin = () => layer_pictures_caller("normal")
document.getElementById("btn_dropin_normal").addEventListener("click", handleNormalDropin);
1 Like

Thank you guys.

That helped me already a lot. Now one more thing is missing.
How can i call a function with multiple parameters?

This is the ducumentation of layer.duplicate but i don’t understand how i can set all 3 parameters?
All the examples never show how to do that.

Somehow i want to call semething like this.

await layer.duplicate(exportdoc, PLACEATBEGINNING, name)

Constants can be accessed via require("photoshop").constants:

Hey Simon,

Thank you very much for your answer.
Slowly getting there.
Now i have 2 questions. :slight_smile:

1. Question

In your sourse there is an example.

const photoshop = require("photoshop");
photoshop.core.executeAsModal(() => {

So there is a function changeMode() to do so.
But how do i change the blendMode of a layer according to that.
layer.changeMode doesn’t exist as a function.

const photoshop = require("photoshop");
photoshop.core.executeAsModal(() => {[0].??changeMode??(photoshop.constants.ColorBlendMode.SCREEN)

How do i solve this?

2. Question

I still don’t get the element placement right with layer.duplicate()

//Im inside a async function here and call this 

const copyLayer = await layer.duplicate()   
const copyLayer = await layer.duplicate(targetDoc)    
const photoshop = require("photoshop");
const copyLayer = await layer.duplicate(targetdoc, photoshop.constants.ElementPlacement.PLACEATBEGINNING)
// copy OK, position WRONG always over the active layer 
const photoshop = require("photoshop");
const copyLayer = await layer.duplicate(targetdoc, photoshop.constants.ElementPlacement.PLACEATBEGINNING, "Test Name")
// copy OK, position WRONG always over the active layer , name OK

What is wrong?

Thank you very much !!!

blendMode is just a property of the Layer class that you can get and set. To be fair, the docs don’t really seem to reflect all the currently available properties. I’d recommend just logging any Layer reference to see what’s available:

For example you can set the mode to darken via:
app.activeDocument.activeLayers[0].blendMode = photoshop.constants.BlendMode.DARKEN

ElementPlacement might be broke, I don’t know.

1 Like

Thank you so much for your effort.
Everything works now how i expected.

And the funny point is they just updated the docs. :slight_smile:
So for everyone who is trying like me to make this parameter work. Its gone.