Ekrank
November 19, 2020, 11:51am
1
Hi,
just two little quick questions.
_ Why :
var doc = app.activeDocument;
var layer_active = doc.activeLayer;
var layer_name = layer_active.name;
don’t work but :
var layer_active = doc.activeLayers[0];
var layer_name = layer_active.name;
yes ?
_ Why :
var doc = app.activeDocument;
var bits_per_channel = String(doc.bitsPerChannel);
don’t work ?
Thank you.
I don’t see any activeLayer or bitsPerChannel properties on the Document specification , where do you take these from?
Ekrank
November 19, 2020, 1:09pm
3
From the old spec. I just want to convert my old script to the new specs.
For activeLayer, i can understand activeLayer = activeLayers[0].
But for bits per channel, i dont found something equal.
I have a function with something like that.
You cannot reuse the old code, with PS 2021 / UXP they introduced a completely new API, at least for the DOM. They’re still working on it, so many features are missing yet. You can achieve almost everything with batchPlay though, which is the “new generation” of ActionManager code.
You could get the channel bits via
const batchPlay = require("photoshop").action.batchPlay;
const deph = await batchPlay(
[
{
"_obj": "get",
"_target": [
{
"_property": "depth"
},
{
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
}
],{
"synchronousExecution": true,
"modalBehavior": "fail"
})[0].depth
1 Like
Ekrank
November 19, 2020, 2:42pm
5
Thank you for the quick answer.
Ok. I understand it’s the beginning and the will add a lot of features in the future.
So, maybe i must wait to convert my plugin.
Thanks again for the answer.
Ekrank
November 23, 2020, 9:12am
6
Nope.
I cant see my mistake.
Why your example with “mode” (find on an other topic) works fine and why my example with “depth” doesnt.
Depth :
const batchPlay = require(“photoshop”).action.batchPlay;
const result = await batchPlay(
[
{
"_obj": "get",
"_target": [
{
"_property": "mode"
},
{
"_ref": "document"
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
"modalBehavior": "fail"
});
var bits_per_channel_t = result[0].depth;
showAlert(bits_per_channel_t.toString());
.
Mode :
const batchPlay = require(“photoshop”).action.batchPlay;
const result = await batchPlay(
[
{
"_obj": "get",
"_target": [
{
"_property": "mode"
},
{
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
"modalBehavior": "fail"
});
var bits_per_channel_t = result[0].mode._value;
showAlert(bits_per_channel_t.toString());
You’re fetching the mode property from the active Document, but then try to extract the depth property from the resulting descriptor - which is undefined of course. That’s the mistake.
Check out the example I posted above
Hi, this is the code I’m using:
async function myDepth() {
const result = await batchPlay(
[{
"_obj": "get",
"_target": [{
"_property": "depth"
},
{
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}], {
"synchronousExecution": false,
"modalBehavior": "fail"
});
var documentDepth = result[0].depth;
app.showAlert(`The Document is in ${documentDepth.toString()} bits`);
}
async function myMode() {
const result = await batchPlay(
[{
"_obj": "get",
"_target": [{
"_property": "mode"
},
{
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}], {
"synchronousExecution": false,
"modalBehavior": "fail"
});
var documentMode = result[0].mode._value;
app.showAlert(`The Document is in ${documentMode.toString()} mode`);
}
Pierre_G:
myDepth()
Pierre_G:
myMode()
Pretty possessive to steal those from the document, isn’t it? Just kidding
Ekrank
November 23, 2020, 4:37pm
10
Ok, it works now.
Thanks again.