I am trying to determine if the top layer is a pixel based layer ( Not any adjustment or text) type of layer.
I am using the following which seems to log the LayerKind as a number. Is there anyway of finding out what these numbers refer to.
const app = require("photoshop").app;
const currentDocument = app.activeDocument
const layers = currentDocument.activeLayers;
const topLayer = layers[0]
console.log(topLayer.kind)
Thanks
1 Like
ddbell
November 7, 2020, 1:52am
2
I just got done making a list for myself just by testing each layer type. I think this is all of them unless there is a #12 for another layer type I forgot to test.
1 - Bitmap layer, including background
2 - Adjustment layer (levels, hue/sat, curves, ect)
3 - Text
4 - Shape
5 - Smart Object
6 - Video
7 - Frame or Group
8 - 3D
9 - Gradient Fill
10 - Pattern Fill
11 - Color Fill
3 Likes
export enum LayerKind {
any = 0,
pixel = 1,
adjustment = 2,
text = 3,
vector = 4,
smartObject = 5,
video = 6,
group = 7,
threeD = 8,
gradient = 9,
pattern = 10,
solidColor = 11,
background = 12,
groupEnd = 13
}
Groups actually occupy two layer spaces internally (group start and group end), so if that’s your setup…
…the layerKind at indices 0-3 would be
0: Pixel (LayerKind 1)
1: Group End (LayerKind 13)
2: Group (LayerKind 7)
Seems like backgrounds only result in LayerKind 12 when they’re the only layer in the document
2 Likes
Thanks @simonhenke and @ddbell this has helped a great deal.
ddbell
November 7, 2020, 4:33pm
5
Thanks for the clarification on 12 and 13. 12 will be helpful for sure trying to figure out if single layer files are flattened or not.
For 7, do you know if there is any way to differentiate between a frame layer or group folder? They both read as 7.
Comparing a group with vector mask with a frame, these are the only differences. Seems like AGMStrokeStyleInfo is the only property to distinguish those two, as a group can’t have a stroke.
So if you check for the layerKind and this property you should be able to identify a frame, theoretically
ddbell
November 7, 2020, 5:37pm
7
Thanks, that will be helpful down the road because I may need to use frames for an upcoming project I have scheduled in a couple of months.
simonhenke:
export enum LayerKind {
any = 0,
pixel = 1,
adjustment = 2,
text = 3,
vector = 4,
smartObject = 5,
video = 6,
group = 7,
threeD = 8,
gradient = 9,
pattern = 10,
solidColor = 11,
background = 12,
groupEnd = 13
}
Is it possible to access LayerKind
from some photoshop.app
or photoshop.core
in a plugin?
You can use this
const app = require("photoshop").app;
var currentDocument = app.activeDocument;
var layers = currentDocument.activeLayers;
var currentLayer = layers[0];
var myLayerKind = currentLayer.kind;
console.log(myLayerKind);
But I want to use for something like:
if (currentLayer.kind === LayerKind.BACKGROUND) {
// <...>
}
Instead of currentLayer.kind === 12
I know I can create my own object, but thought maybe these enums are accessible somehow
Here in the docs Adobe even has this as an example:
if (layer.kind === LayerKind.TEXT) {
...
}
1 Like
I am returning to this because I would like to find out the actual type of adjustment layer.
For Example…
If active layer = curves then do something…
I have this function called LayerType which outputs the following. I can see “curves” in the output so I am thinking I could use that but not quite sure how to access it.
1. legacyContentData: ArrayBuffer(20) {}
2. _obj: "curves"
3. __proto__: Object
async function LayerType(){
const result = await batchPlay(
[
{
"_obj": "get",
"_target": [
{
"_ref": "layer",
"_enum": "ordinal",
"_value": "targetEnum"
},
{
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
"modalBehavior": "fail"
});
const pinned = result[0].adjustment;
console.log(pinned)
}
Any help would be appreciated
Thanks
I have manged to figure it out with this new function
async function LayerType(){
const result = await batchPlay(
[
{
"_obj": "get",
"_target": [
{
"_ref": "layer",
"_id": 21
},
{
"_ref": "document",
"_id": 246
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
"modalBehavior": "fail"
});
const pinned = result[0].adjustment[0]._obj;
console.log(pinned)
}
dcotto
July 22, 2021, 10:18pm
13
could you help me out. i saw the documentation as well and wish to do the samething and compare to LayerKind.TEXT. what exactly am i suppose to do to get this to work?
dcotto
July 23, 2021, 1:52am
14
this is what i wish to know or what is the way to access layerkind?
liuxiao
September 10, 2021, 2:14am
15
Yes, but it is not work with group layer