# Adjustment Layer Getting Preset Kind

**URL:** <https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590>\
**Category:** Photoshop\
**Tags:** javascript\
**Created:** [April 28, 2022, 8:26am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590 "2022-04-28T08:26:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gibsoneditions](https://avatars.discourse-cdn.com/v4/letter/g/e79b87/32.png) [@gibsoneditions](https://forums.creativeclouddeveloper.com/u/gibsoneditions)\
**Post date:** [April 28, 2022, 8:26am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/1 "2022-04-28T08:26:47Z")

</div>

I am trying to get the PresetKind to establish if an adjustment layer specifically curves have no adjustments applied to them. I made the following getter but it doesn’t want to work for me. Any help on where the bug might be would be much appreciated

```auto
const app = require("photoshop").app;
const batchPlay = require("photoshop").action.batchPlay;

Object.defineProperty(require("photoshop").app.Layer.prototype, 
"presetKindType",
{
    get: () =>{
        const result = batchPlay(
            [
               {
                  _obj: "get",
                  _target: [
                     {
                        _property: "presetKindType"
                        
                     },
                     {
                        _ref: "adjustmentLayer",
                        _enum: "ordinal",
                         _value: "targetEnum"
                     }
                  ],
                  _options: {
                     dialogOptions: "dontDisplay"
                  }
               }
            ],{
               synchronousExecution: true,
               modalBehavior: "fail"
            });
            return result[0].presetKindType._value; 
    }
})

```

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [April 28, 2022, 8:40am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/2 "2022-04-28T08:40:51Z")

</div>

What do you mean by _doesn’t work_?  
What’s the actual result? What’s the expected result?

---

<div class="post-metadata">

**Author:** ![gibsoneditions](https://avatars.discourse-cdn.com/v4/letter/g/e79b87/32.png) [@gibsoneditions](https://forums.creativeclouddeveloper.com/u/gibsoneditions)\
**Post date:** [April 28, 2022, 9:12am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/3 "2022-04-28T09:12:19Z")

</div>

Id like to get the result of the enumeration value i.e. “presetKindCustom” to establish if the curve has any points or is empty…

---

<div class="post-metadata">

**Author:** ![gibsoneditions](https://avatars.discourse-cdn.com/v4/letter/g/e79b87/32.png) [@gibsoneditions](https://forums.creativeclouddeveloper.com/u/gibsoneditions)\
**Post date:** [April 28, 2022, 9:17am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/4 "2022-04-28T09:17:04Z")

</div>

When i run it i get the response " **The command “Get” is not currently available.**"

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [April 28, 2022, 9:34am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/5 "2022-04-28T09:34:01Z")

</div>

> [@gibsoneditions](#):
>
> " **The command “Get” is not currently available.**"

Usually it’s because of the wrong descriptor or more likely wrong property you try to interact with. In this case it’s probably `presetKindType` or `adjustmentLayer` (did you try just `layer`?). What does Alchemist show for that layer property?

I know, this is a very annoying error which doesn’t actually tell you anything useful. Same happens with `set` or any other `_obj`

---

<div class="post-metadata">

**Author:** ![gibsoneditions](https://avatars.discourse-cdn.com/v4/letter/g/e79b87/32.png) [@gibsoneditions](https://forums.creativeclouddeveloper.com/u/gibsoneditions)\
**Post date:** [April 28, 2022, 10:19am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/6 "2022-04-28T10:19:00Z")

</div>

It was quite tricky to get the code out of alchemist took a couple of goes. see below

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

const result = await batchPlay(
[
   {
      _obj: "set",
      _target: [
         {
            _ref: "adjustmentLayer",
            _enum: "ordinal",
            _value: "targetEnum"
         }
      ],
      to: {
         _obj: "curves",
         presetKind: {
            _enum: "presetKindType",
            _value: "presetKindCustom"
         },
         adjustment: [
            {
               _obj: "curvesAdjustment",
               channel: {
                  _ref: "channel",
                  _enum: "channel",
                  _value: "composite"
               },
               curve: [
                  {
                     _obj: "paint",
                     horizontal: 0,
                     vertical: 0
                  },
                  {
                     _obj: "paint",
                     horizontal: 140,
                     vertical: 77
                  },
                  {
                     _obj: "paint",
                     horizontal: 255,
                     vertical: 255
                  }
               ]
            }
         ]
      },
      _options: {
         dialogOptions: "dontDisplay"
      }
   }
],{
   synchronousExecution: false,
   modalBehavior: "fail"
});

```

---

<div class="post-metadata">

**Author:** ![gibsoneditions](https://avatars.discourse-cdn.com/v4/letter/g/e79b87/32.png) [@gibsoneditions](https://forums.creativeclouddeveloper.com/u/gibsoneditions)\
**Post date:** [April 28, 2022, 10:32am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/7 "2022-04-28T10:32:22Z")

</div>

```auto
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"
});

```

---

<div class="post-metadata">

**Author:** ![gibsoneditions](https://avatars.discourse-cdn.com/v4/letter/g/e79b87/32.png) [@gibsoneditions](https://forums.creativeclouddeveloper.com/u/gibsoneditions)\
**Post date:** [April 28, 2022, 10:38am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/8 "2022-04-28T10:38:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [April 28, 2022, 10:55am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/9 "2022-04-28T10:55:38Z")

</div>

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

```auto
    {
        _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:

```auto
        {
          "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`:

```auto
        {
          "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"`

---

<div class="post-metadata">

**Author:** ![gibsoneditions](https://avatars.discourse-cdn.com/v4/letter/g/e79b87/32.png) [@gibsoneditions](https://forums.creativeclouddeveloper.com/u/gibsoneditions)\
**Post date:** [April 28, 2022, 11:16am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/10 "2022-04-28T11:16:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gibsoneditions](https://avatars.discourse-cdn.com/v4/letter/g/e79b87/32.png) [@gibsoneditions](https://forums.creativeclouddeveloper.com/u/gibsoneditions)\
**Post date:** [April 28, 2022, 11:34am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/11 "2022-04-28T11:34:15Z")

</div>

Came up with this in the end using your Json idea

````auto
     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
````

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [April 28, 2022, 11:39am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/12 "2022-04-28T11:39:44Z")

</div>

> [@gibsoneditions](#):
>
> `JSON.parse(result[0].json).layers[0]`

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

```auto
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:

```auto
Group 1
Group 2
 '- Curves

```

---

<div class="post-metadata">

**Author:** ![gibsoneditions](https://avatars.discourse-cdn.com/v4/letter/g/e79b87/32.png) [@gibsoneditions](https://forums.creativeclouddeveloper.com/u/gibsoneditions)\
**Post date:** [April 28, 2022, 11:48am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/13 "2022-04-28T11:48:49Z")

</div>

Ah ha i see, ill have a go

---

<div class="post-metadata">

**Author:** ![gibsoneditions](https://avatars.discourse-cdn.com/v4/letter/g/e79b87/32.png) [@gibsoneditions](https://forums.creativeclouddeveloper.com/u/gibsoneditions)\
**Post date:** [April 28, 2022, 12:46pm UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/14 "2022-04-28T12:46:00Z")

</div>

I’m guessing something like this?

````auto
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)
   }

}```
````

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [April 28, 2022, 12:49pm UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/15 "2022-04-28T12:49:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gibsoneditions](https://avatars.discourse-cdn.com/v4/letter/g/e79b87/32.png) [@gibsoneditions](https://forums.creativeclouddeveloper.com/u/gibsoneditions)\
**Post date:** [April 28, 2022, 12:52pm UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/16 "2022-04-28T12:52:25Z")

</div>

That would be wonderful, Many thanks for your help

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [April 28, 2022, 4:20pm UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/17 "2022-04-28T16:20:49Z")

</div>

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:

```javascript
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

```

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [April 29, 2022, 10:12am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/18 "2022-04-29T10:12:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [April 29, 2022, 11:08am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/19 "2022-04-29T11:08:39Z")

</div>

In my example [here](http://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/9) it is with `layer` and for whatever reason it returns structure like mentioned [here](http://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/12) 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [April 29, 2022, 11:36am UTC](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590/20 "2022-04-29T11:36:19Z")

</div>

Json property has additional flags see: [Photoshop Kevlar API Additions for Generator · adobe-photoshop/generator-core Wiki · GitHub](https://github.com/adobe-photoshop/generator-core/wiki/Photoshop-Kevlar-API-Additions-for-Generator/255080b2daeadc6e23943daa825786740ce23a58#senddocumentinfotonetworkclient) (needs to be transformed for batchPlay)

Alchemist is using it here: [alchemist/GetInfo.ts at master · jardicc/alchemist · GitHub](https://github.com/jardicc/alchemist/blob/master/src/inspector/classes/GetInfo.ts#L283) when you select “generator” option in inspector.

[Next page](https://forums.creativeclouddeveloper.com/t/adjustment-layer-getting-preset-kind/4590.md?page=2)
