Adjustment Layer Getting Preset Kind

const batchPlay = require("photoshop").action.batchPlay;

const result = await batchPlay(
[
   {
      _obj: "make",
      _target: [
         {
            _ref: "adjustmentLayer"
         }
      ],
      using: {
         _obj: "adjustmentLayer",
         type: {
            _obj: "curves",
            presetKind: {
               _enum: "presetKindType",
               _value: "presetKindDefault"
            }
         }
      },
      _options: {
         dialogOptions: "dontDisplay"
      }
   }
],{
   synchronousExecution: false,
   modalBehavior: "fail"
});

I can’t seem to read the property via Alchemist inspector… I can only find it using the listener when creating a curve layer. I tried swapping out adjustmentLayer for Layer but to no avail

Not sure if it’s the only way, but you can get this from layers json property.

    {
        _obj: "get",
        _target: [
            {_property: "json"},
            { _ref: "layer",_enum: "ordinal", _value: "targetEnum"},
        ],
        _options: {dialogOptions: "dontDisplay"}
    }

There you’ll need to JSON.parse(propertyValue) and you’ll find layers. Then you could recursively iterate through these layers and find the one you need by ID. You’ll get something like that:

        {
          "id": 18,
          "index": 4,
          "type": "adjustmentLayer",
          "name": "Curves 1",
          "bounds": {"top": 0, "left": 0, "bottom": 2048, "right": 3072},
          "visible": true,
          "clipped": false,
          "adjustment": {
            "presetKind": "presetKindCustom",
            "adjustment": [
              {
                "channel": "composite",
                "curve": [
                  {"horizontal": 0, "vertical": 0},
                  {"horizontal": 147, "vertical": 106},
                  {"horizontal": 219, "vertical": 136},
                  {"horizontal": 255, "vertical": 255}
                ]
              }
            ],
            "class": "curves"
          },
          "mask": {
            "bounds": {"top": 0, "left": 0, "bottom": 2048, "right": 3072},
            "extendWithWhite": true
          },
          "generatorSettings": false
        }

Just checked and even if you reset all points on the curve, it still gives custom, but without adjustment:

        {
          "id": 18,
          "index": 4,
          "type": "adjustmentLayer",
          "name": "Curves 1",
          "bounds": {"top": 0, "left": 0, "bottom": 2048, "right": 3072},
          "visible": true,
          "clipped": false,
          "adjustment": {
            "presetKind": "presetKindCustom",
            "class": "curves"
          },
          "mask": {
            "bounds": {"top": 0, "left": 0, "bottom": 2048, "right": 3072},
            "extendWithWhite": true
          },
          "generatorSettings": false
        }

Freshly created layer has exact same structure, but "presetKind": "presetKindDefault"

Thats really useful, thanks so much for your help. Interesting the presetKind doesn’t revert to default.

Came up with this in the end using your Json idea

     const batchPlay = require("photoshop").action.batchPlay;
     function getCurve() {
      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 getCurve = JSON.parse(result[0].json).layers[0].adjustment.presetKind;
      console.log(getCurve)
  }

![Screenshot 2022-04-28 at 13.35.10|476x292](upload://xkPcXRSlG0D2eO2tfQhvqVH54Mp.png)


```These are the sort of results it brings

I intentionally mentioned recursive iteration to get a layer. My layers stucture is something like:

Group 1
 |- Layer 1
 '- Layer 2
Layer 3
Layer 4
Group 2
 |- Layer 5
 |- Curves << ACTIVE LAYER I TRY TO GET
 '- Layer 6
Layer 7
Background

And JSON.parse(result[0].json) gave me structure like this:

Group 1
Group 2
 '- Curves

Ah ha i see, ill have a go

I’m guessing something like this?

const batchPlay = require("photoshop").action.batchPlay;
    
      const result = batchPlay(
          [{
              "_obj": "get",
              "_target": [{
                      "_property": "json"
                  },
                  {
                      "_ref": "document",
                      "_enum": "ordinal",
                      "_value": "targetEnum"
                  }
              ],
              "_options": {
                  "dialogOptions": "dontDisplay"
              }
          }], {
              "synchronousExecution": true,
              "modalBehavior": "fail"
          });
          let jsonProp = result[0].json;
          console.log("jsonProp", jsonProp)
          let jsonData = JSON.parse(jsonProp);
          console.log("jsonData", jsonData)
     const lyrs = jsonData.layers
     console.log(lyrs)

for(i = 0; i < lyrs.length; i++){
 //  console.log(lyrs[i].type)
   if(lyrs[i].type == "adjustmentLayer"){

      console.log(lyrs[i].adjustment.presetKind)
      console.log(lyrs[i].id)
   }


}```

I would write a proper recursive function to search through the whole tree until it hits the layer you’re looking for. I will need this also, so if you can wait a bit, I might provide it in a day or sooner. But if it doesn’t return layers, that are located inside the layer I’m looking for, then maybe this would not be an option for me. I will check this later

That would be wonderful, Many thanks for your help

OK, so for me this approach is a no go, because that JSON does not contain children layers, but anyway I quickly wrote small function, which allows you to search for an object in the array with similar structure. This will return first match or null if not found:

const testArray = [
    {
        "name": "Title 1", "id": "id01", "children": [
            {"name": "Title 5", "id": "id05"},
            {"name": "Title 6", "id": "id06"},
            {"name": "Title 7", "id": "id07"},
            {
                "name": "Title 3", "id": "id08", "children": [
                    {"name": "Title 8", "id": "id08"},
                    {"name": "Title 9", "id": "id09"},
                    {"name": "Title 10", "id": "id10"},
                    {"name": "Title 11", "id": "id11"},
                ]
            },
        ]
    },
    {"name": "Title 2", "id": "id02"},
    {"name": "Title 3", "id": "id03"},
    {
        "name": "Title 3", "id": "id04", "children": [
            {"name": "Title 1", "id": "id12"},
            {"name": "Title 8", "id": "id13"},
            {"name": "Title 3", "id": "id14"},
            {"name": "Title 3", "id": "id15"},
        ]
    },
]

const searchRecursive = ({items, childrenKey, searchKey, searchValue}) => {
    let result = null

    for (const item of items) {
        if (item[searchKey] === searchValue) {
            result = item
            break
        }

        if (!result && typeof item[childrenKey] === "object" && item[childrenKey].length) {
            result = searchRecursive({items: item[childrenKey], childrenKey, searchKey, searchValue})
        }
    }

    return result
}

console.log(searchRecursive({
    items: testArray,
    childrenKey: "children",
    searchKey: "id",
    searchValue: "id02",
})) // { name: 'Title 2', id: 'id02' }

console.log(searchRecursive({
    items: testArray,
    childrenKey: "children",
    searchKey: "name",
    searchValue: "Title 8",
})) // {"name": "Title 8", "id": "id08"}

console.log(searchRecursive({
    items: testArray,
    childrenKey: "children",
    searchKey: "id",
    searchValue: "id12",
})) // {"name": "Title 1", "id": "id12"}

console.log(searchRecursive({
    items: testArray,
    childrenKey: "children",
    searchKey: "name",
    searchValue: "Title 8",
})) // { name: 'Title 8', id: 'id08' }

console.log(searchRecursive({
    items: testArray,
    childrenKey: "children",
    searchKey: "name",
    searchValue: "Title 88",
})) // null

console.log(searchRecursive({
    items: testArray,
    childrenKey: "nonExistantKey",
    searchKey: "name",
    searchValue: "Title 8",
})) // null

What if you get json property of layer instead of document?

In my example here it is with layer and for whatever reason it returns structure like mentioned here :man_shrugging:

Json property has additional flags see: Photoshop Kevlar API Additions for Generator · adobe-photoshop/generator-core Wiki · GitHub (needs to be transformed for batchPlay)

Alchemist is using it here: alchemist/GetInfo.ts at master · jardicc/alchemist · GitHub when you select “generator” option in inspector.

1 Like

I believe this might be related to my other question here. At first glance it looks like it might also be a bit too advanced for me, but will need to play with these flags

Looks very powerful, but not completely sure how to implement it. Would you have a simple example?

apologies, just realised you mean the example is in alchemist by using the generator setting. Many Thanks

This works, would like to drill down for specific properties like the documentation…

const batchPlay = require("photoshop").action.batchPlay;

const result = await batchPlay(
[
   {
      _obj: "get",
      _target: [
         {
            _property: "json"
         },
         {
            _ref: "document",
            _id: 219
         }
      ],
      layerInfo: true,
      includeAncestors: true,
      _options: {
         dialogOptions: "dontDisplay"
      }
   }
],{
   synchronousExecution: false,
   modalBehavior: "fail"
});
const pinned = result[0].json.layers[0].type;


{"version":"1.6.1","timeStamp":0.000,"count":0,"id":219,"layers":[{"id":9,"index":13,"type":"layerSection","name":"BACKGROUND","bounds":{"top":0,"left":0,"bottom":0,"right":0},"visible":true,"clipped":false,"blendOptions":{"mode":"passThrough"},"generatorSettings":false,"id":9,"index":13,"layers":[{"id":14,"index":12,"type":"adjustmentLayer","name":"CV CC","bounds":{"top":0,"left":0,"bottom":5956,"right":3978},"visible":true,"clipped":false,"adjustment":{"presetKind":"presetKindUserDefined","class":"curves"},"generatorSettings":false},{"id":13,"index":11,"type":"adjustmentLayer","name":"CV H","bounds":{"top":0,"left":0,"bottom":5956,"right":3978},"visible":true,"clipped":false,"adjustment":{"presetKind":"presetKindUserDefined","using":"","class":"curves"},"generatorSettings":false},{"id":12,"index":10,"type":"adjustmentLayer","name":"CV SHDW","bounds":{"top":0,"left":0,"bottom":5956,"right":3978},"visible":true,"clipped":false,"adjustment":{"presetKind":"presetKindUserDefined","using":"","class":"curves"},"generatorSettings":false},{"id":11,"index":9,"type":"adjustmentLayer","name":"CV MID","bounds":{"top":0,"left":0,"bottom":5956,"right":3978},"visible":true,"clipped":false,"adjustment":{"presetKind":"presetKindUserDefined","using":"","class":"curves"},"generatorSettings":false}]},{"id":3,"index":7,"type":"layerSection","name":"PRODUCT","bounds":{"top":0,"left":0,"bottom":0,"right":0},"visible":true,"clipped":false,"blendOptions":{"mode":"passThrough"},"generatorSettings":false,"id":3,"index":7,"layers":[{"id":8,"index":6,"type":"adjustmentLayer","name":"CV CC","bounds":{"top":0,"left":0,"bottom":5956,"right":3978},"visible":true,"clipped":false,"adjustment":{"presetKind":"presetKindUserDefined","class":"curves"},"generatorSettings":false},{"id":7,"index":5,"type":"adjustmentLayer","name":"CV H","bounds":{"top":0,"left":0,"bottom":5956,"right":3978},"visible":true,"clipped":false,"adjustment":{"presetKind":"presetKindUserDefined","using":"","class":"curves"},"generatorSettings":false},{"id":6,"index":4,"type":"adjustmentLayer","name":"CV SHDW","bounds":{"top":0,"left":0,"bottom":5956,"right":3978},"visible":true,"clipped":false,"adjustment":{"presetKind":"presetKindUserDefined","using":"","class":"curves"},"generatorSettings":false},{"id":5,"index":3,"type":"adjustmentLayer","name":"CV MID","bounds":{"top":0,"left":0,"bottom":5956,"right":3978},"visible":true,"clipped":false,"adjustment":{"presetKind":"presetKindUserDefined","using":"","class":"curves"},"generatorSettings":false}]},{"id":2,"index":1,"type":"layer","name":"Retouch","protection":{"position":true},"bounds":{"top":0,"left":0,"bottom":0,"right":0},"visible":true,"clipped":false,"pixels":true,"generatorSettings":false},{"id":1,"index":0,"type":"backgroundLayer","name":"Background","protection":{"transparency":true,"position":true,"artboardAutonest":true},"bounds":{"top":0,"left":0,"bottom":5956,"right":3978},"visible":true,"clipped":false,"pixels":true,"generatorSettings":false}]}```

Was thinking it could be something like this…

const batchPlay = require("photoshop").action.batchPlay;

const result = await batchPlay(
[
   {
      _obj: "get",
      _target: [
         {
            _property: "json"
         },
         {
            _ref: "document",
            _id: 219
         }
      ],
      layerInfo: {
            type: true

      },
      includeAncestors: true,
      _options: {
         dialogOptions: "dontDisplay"
      }
   }
],{
   synchronousExecution: false,
   modalBehavior: "fail"
});

but it doesn’t work

There are even flags to get info only for layers that you are interested in.