Is it possible to get the adjustment value of, for example, a brightness adjustment layer as an json object?
I tried with Alchemist and some loops / maps in the console but wasn’t lucky.
Yes it’s possible. Why would you need a JSON object for that ?
Does not neccessarily need to be a json object. It could be anything. I just need to sync the adjustment values of the layers to the adjustments in my plugin when for example a document is opened or selected.
Ok, then try to call this function on a Brightness/Contrast layer.
function getBrightness() {
const result = batchPlay(
[{
"_obj": "get",
"_target": [{
"_property": "json"
},
{
"_ref": "layer",
"_enum": "ordinal",
"_value": "targetEnum"
},
{
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}], {
"synchronousExecution": true,
"modalBehavior": "fail"
});
const getBrightness = JSON.parse(result[0].json).layers[0].adjustment.brightness;
console.log(getBrightness)
}
You made my day Pierre! Works like a charm, thank you so much for helping me out!
You’re most welcome!
Note: individual channels in curves are not readable. Unless something changed since last time.
I noticed many adjustment layers are not readable, like exposure, levels etc… I always get undefined back unless i change something.
It seems to have to do something with the paradoxon that photoshop does everything twice, like setting and getting objects. I can see in the console that on layers where reading the values works, the first get event reads undefined and on the second get event it gets the value.
On layers where it doesn’t work it gets undefined twice. When i change something manually it gets the value on the first get event but it’s undefined on the second get event.
That drives me nuts. I mean, we are building panels for non-destructive image editing and we can’t read the values from adjustment layers? I assume that should be a core functionality.
How could we work around this? Any ideas?
I don’t see any problems.
Would be interesting to see how you setup a “getter” with batchPlay…
I do it exactly as advised by you (thank you again), but i’m using a corresponding json object.
For example for a exposure adjustment layer, from which i want to extract the gamma value:
...JSON.parse(result[0].json).layers[0].adjustment.gammaCorrection
This works.
In your batchPlay, make sure to keep “synchronousExecution”: true
I have “synchronousExecution”: true, but it doesn’t work here. May have a problem elsewhere. Will triple check.
Maybe you’re not retrieving the correct layer info…
I had a problem with async. I reduced the function to the single gamma “getter” and now it works. Man, having a hard time understanding async code after sync CEP. Sorry for bothering you and thanks again Pierre!
Not a problem at all, glad you sorted it out
Now after taking a deep dive into ES6 promises i finally got it working. Yaaaay!
Now i’m struggling with layers that have deeper hirarchical structures like levels adjustment layers.
This for example is what Alchemist gives me when changing the values on a brightness layer:
const batchPlay = require("photoshop").action.batchPlay;
const result = await batchPlay(
[
{
"_obj": "set",
"_target": [
{
"_ref": "adjustmentLayer",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"to": {
"_obj": "brightnessEvent",
"brightness": 37,
"center": 6,
"useLegacy": false
},
"_isCommand": false,
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
"modalBehavior": "fail"
});
And this is what it gives me on a levels layer:
const batchPlay = require(“photoshop”).action.batchPlay;
const result = await batchPlay(
[
{
"_obj": "set",
"_target": [
{
"_ref": "adjustmentLayer",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"to": {
"_obj": "levels",
"adjustment": [
{
"_obj": "levelsAdjustment",
"channel": {
"_ref": "channel",
"_enum": "channel",
"_value": "composite"
},
"gamma": 0.84
}
]
},
"_isCommand": false,
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
"modalBehavior": "fail"
});
Maybe it’s just because i bombed my brain with promises too much today…but i don’t get it.
@Pierre_G could you help me out…again?
Sure! How can I help ?
Your code above works. Note that these lines are “setter”. Will send some settings to PS layers.
PS: because they are “setter” you won’t need const result
Yes i know these are “setters”. I use them for getting the json object needed for the “getters” for your code.
What i need to know is how to access the levels layer for setting the composite and single color channels.
Oh, you mean something like this ?
(here for a Levels Adj. Layer)
let result = await batchPlay(
[{
"_obj": "get",
"_target": [{
"_property": "json"
},
{
"_ref": "layer",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"_options": {}
}], {});
let pinned = result[0].json;
console.log(JSON.parse(pinned).layers["0"].adjustment.adjustment[0].channel)
console.log(JSON.parse(pinned).layers["0"].adjustment.adjustment[0].gamma)
.
PS this below returns an Array of Channels that belongs to Levels Adj. Layer structure
console.log(JSON.parse(pinned).layers["0"].adjustment.adjustment)
etc. etc.
Simple thing to do is use the Dev Console and explore the properties you are interested in:
You’re awesome Pierre! Thank you again. Let me know where your PayPal donation button is