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.
////////////////////////////// LAYER PICTURES ////////////////////////////////////////
function layer_pictures_caller() {
try {
require('photoshop').core.executeAsModal(layer_pictures);
}
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 = closelater.name
const copyLayer = await layer.duplicate(targetdoc)
closelater.closeWithoutSaving()
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!
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.
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.
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()
//OK
const copyLayer = await layer.duplicate(targetDoc)
//OK
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
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: