How to get layer blendRange property?

With Alchemist I found how to set blendRange, but I can’t figure out how to get it. Tried variations of such descriptor:

{
    "_obj": "get",
    "_target": [
        { "_property": "blendRange" },
        {
            "_ref": "channel",
            "_enum": "channel",
            "_value": "gray"
        },
        {
            "_ref": "layer",
            "_enum": "ordinal",
            "_value": "targetEnum"
        }
    ]
}

Also just for layer:

{
    "_obj": "get",
    "_target": [
        { "_property": "blendRange" },
        {
            "_ref": "layer",
            "_enum": "ordinal",
            "_value": "targetEnum"
        }
    ]
}

And just for channel:

{
    "_obj": "get",
    "_target": [
        { "_property": "blendRange" },
        {
            "_ref": "layer",
            "_enum": "ordinal",
            "_value": "targetEnum"
        }
    ]
}

None worked. Error:

The command “Get” is not currently available.

Any way to get Blend if... data?

is this a property you want to get ?

async function getLayerProps() {
   const result = await batchPlay(
      [
         {
            _obj: "get",
            _target: [
               {
                  _property: "json"
               },
               {
                  _ref: "layer",
                  _id: 2 // something layer id
               },
               {
                  _ref: "document",
                  _id: 109 // somthing document id
               }
            ],
            _options: {
               dialogOptions: "dontDisplay"
            }
         }
      ],
      {}
   );
   return result[0];
}

(, () => {
   executeAsModal(async () => {
      try {
         const n = await getLayerProps();
         const prop = JSON.parse(n.json);
         // getting layer properties
         console.log(prop);
      } catch (e) {
         await app.showAlert(e);
      }
   }, {"commandName": "Action Commands"});
})();
1 Like

Yes :slightly_smiling_face: After I got to bed yesterday, I remembered about this JSON property too. Will test a bit later today and let you know :pray:

Nope, desn’t really work :frowning: If there are layers in a group and you want to get any of those, it always returns the parent (group) layer data :confused:

My structure:

- Layer
- Group
|- GroupLayer1
|- GroupLayer2
'- GroupLayer3

If I select Group, it returns data for Group, but…

  • If I select Layer, it returns data for both Layer and Group
  • If I select any of the GroupLayerX, it returns data always just for Group

It doesn’t matter if I try to get data by active layers or by passing _index or _id

I guess I can get the data from the document json property, but I’ll have to search recursively through a layer tree to find the layers I need…

No need to search. In JSON property descriptor you can pick the layerID you want to. So you will get only one layer.

What do you mean? At least what I’ve tried, didn’t work. It always returns group layer:

It doesn’t matter if I try to get data by active layers or by passing _index or _id

It does not use the reference. This is the same: Photoshop Kevlar API Additions for Generator · adobe-photoshop/generator-core Wiki · GitHub

OK, I really tried understanding that piece of code, but I guess without ActionScript knowledge it’s a bit too much. I still have no idea how to request specific layer JSON in UXP :confused:

You can check Alchemist… it generates template code for you:

Or json property of layer directly

Yes, so that’s what I did as you suggest in the first option, to get document json, but then I need to parse all layers tree.

The second option to get by layer ID directly - I tried, and as I mentioned, it doesn’t really work. Responses don’t make much sense to me if I’m honest. For example this:

This is the response, for the top layer Gradient Fill 2 copy 4 (contains first group ColorrWheel copy and second group with selected sub-layer):

{
  "version": "1.6.1",
  "timeStamp": 0,
  "count": 0,
  "id": 59,
  "file": "U:\\Creative Cloud Files\\_Stuff\\ColorWheel.psd",
  "bounds": {
    "top": 0,
    "left": 0,
    "bottom": 1400,
    "right": 1168
  },
  "selection": [
    7
  ],
  "resolution": 72,
  "globalLight": {
    "angle": 90,
    "altitude": 30
  },
  "generatorSettings": false,
  "profile": "Untagged RGB",
  "mode": "RGBColor",
  "depth": 8,
  "layers": [
    {
      "id": 29,
      "index": 20,
      "type": "layerSection",
      "name": "ColorrWheel copy",
      "bounds": {
        "top": 0,
        "left": -2,
        "bottom": 1400,
        "right": 1170
      },
      "boundsWithFX": {
        "top": 0,
        "left": -2,
        "bottom": 1400,
        "right": 1170
      },
      "visible": false,
      "clipped": false,
      "blendOptions": {
        "mode": "passThrough"
      },
      "generatorSettings": false
    },
    {
      "id": 16,
      "index": 9,
      "type": "layerSection",
      "name": "ColorrWheel",
      "bounds": {
        "top": 0,
        "left": -2,
        "bottom": 1400,
        "right": 1170
      },
      "boundsWithFX": {
        "top": 0,
        "left": -2,
        "bottom": 1400,
        "right": 1170
      },
      "visible": true,
      "clipped": false,
      "blendOptions": {
        "mode": "passThrough"
      },
      "generatorSettings": false,
      "layers": [
        {
          "id": 14,
          "index": 7,
          "type": "adjustmentLayer",
          "name": "Gradient Fill 2 copy 4",
          "bounds": {
            "top": 1250,
            "left": 0,
            "bottom": 1300,
            "right": 1170
          },
          "boundsWithFX": {
            "top": 1250,
            "left": 0,
            "bottom": 1300,
            "right": 1170
          },
          "visible": true,
          "clipped": false,
          "fill": {
            "dither": false,
            "reverse": true,
            "gradientsInterpolationMethod": "smooth",
            "gradientAspectRatio": 1,
            "angle": {
              "value": 0,
              "units": "angleUnit"
            },
            "type": "linear",
            "align": true,
            "scale": {
              "value": 99.9997,
              "units": "percentUnit"
            },
            "offset": {
              "horizontal": {
                "value": 0,
                "units": "percentUnit"
              },
              "vertical": {
                "value": 0,
                "units": "percentUnit"
              }
            },
            "gradient": {
              "name": "Custom",
              "gradientForm": "customStops",
              "interfaceIconFrameDimmed": 4096,
              "colors": [
                {
                  "color": {
                    "red": 0,
                    "green": 0,
                    "blue": 255
                  },
                  "type": "userStop",
                  "location": 0,
                  "midpoint": 50
                },
                {
                  "color": {
                    "red": 255,
                    "green": 255,
                    "blue": 0
                  },
                  "type": "userStop",
                  "location": 4096,
                  "midpoint": 50
                }
              ],
              "transparency": [
                {
                  "opacity": {
                    "value": 100,
                    "units": "percentUnit"
                  },
                  "location": 0,
                  "midpoint": 50
                },
                {
                  "opacity": {
                    "value": 100,
                    "units": "percentUnit"
                  },
                  "location": 4096,
                  "midpoint": 50
                }
              ]
            },
            "class": "gradientLayer"
          },
          "mask": {
            "bounds": {
              "top": 1250,
              "left": 0,
              "bottom": 1300,
              "right": 1170
            }
          },
          "generatorSettings": false
        }
      ]
    }
  ]
}

This is the response, for the layer Gradient Fill 4 (contains all three top-level layers/groups):

{
  "version": "1.6.1",
  "timeStamp": 0,
  "count": 0,
  "id": 59,
  "file": "U:\\Creative Cloud Files\\_Stuff\\ColorWheel.psd",
  "bounds": {
    "top": 0,
    "left": 0,
    "bottom": 1400,
    "right": 1168
  },
  "selection": [
    10
  ],
  "resolution": 72,
  "globalLight": {
    "angle": 90,
    "altitude": 30
  },
  "generatorSettings": false,
  "profile": "Untagged RGB",
  "mode": "RGBColor",
  "depth": 8,
  "layers": [
    {
      "id": 29,
      "index": 20,
      "type": "layerSection",
      "name": "ColorrWheel copy",
      "bounds": {
        "top": 0,
        "left": -2,
        "bottom": 1400,
        "right": 1170
      },
      "boundsWithFX": {
        "top": 0,
        "left": -2,
        "bottom": 1400,
        "right": 1170
      },
      "visible": false,
      "clipped": false,
      "blendOptions": {
        "mode": "passThrough"
      },
      "generatorSettings": false
    },
    {
      "id": 19,
      "index": 10,
      "type": "adjustmentLayer",
      "name": "Gradient Fill 4",
      "bounds": {
        "top": 0,
        "left": 0,
        "bottom": 1400,
        "right": 1168
      },
      "boundsWithFX": {
        "top": 0,
        "left": 0,
        "bottom": 1400,
        "right": 1168
      },
      "visible": true,
      "clipped": false,
      "blendOptions": {
        "blendRange": [
          {
            "channel": "gray",
            "srcBlackMin": 43,
            "srcBlackMax": 62,
            "srcWhiteMin": 167,
            "srcWhiteMax": 190,
            "destBlackMin": 0,
            "destBlackMax": 0,
            "destWhiteMin": 255,
            "desaturate": 255
          }
        ]
      },
      "fill": {
        "dither": false,
        "reverse": false,
        "gradientsInterpolationMethod": "smooth",
        "gradientAspectRatio": 1,
        "angle": {
          "value": 90,
          "units": "angleUnit"
        },
        "type": "linear",
        "align": true,
        "scale": {
          "value": 100,
          "units": "percentUnit"
        },
        "offset": {
          "horizontal": {
            "value": 0,
            "units": "percentUnit"
          },
          "vertical": {
            "value": 0,
            "units": "percentUnit"
          }
        },
        "gradient": {
          "name": "Black, White",
          "gradientForm": "customStops",
          "interfaceIconFrameDimmed": 4096,
          "colors": [
            {
              "color": {
                "redFloat": -0.0000016205,
                "greenFloat": 5.59524e-7,
                "blueFloat": -6.69675e-7
              },
              "type": "userStop",
              "location": 0,
              "midpoint": 50
            },
            {
              "color": {
                "redFloat": 1,
                "greenFloat": 0.999999,
                "blueFloat": 1
              },
              "type": "userStop",
              "location": 4096,
              "midpoint": 50
            }
          ],
          "transparency": [
            {
              "opacity": {
                "value": 100,
                "units": "percentUnit"
              },
              "location": 0,
              "midpoint": 50
            },
            {
              "opacity": {
                "value": 100,
                "units": "percentUnit"
              },
              "location": 4096,
              "midpoint": 50
            }
          ]
        },
        "class": "gradientLayer"
      },
      "mask": {
        "bounds": {
          "top": 0,
          "left": 0,
          "bottom": 1400,
          "right": 1168
        },
        "extendWithWhite": true
      },
      "generatorSettings": false
    },
    {
      "id": 16,
      "index": 9,
      "type": "layerSection",
      "name": "ColorrWheel",
      "bounds": {
        "top": 0,
        "left": -2,
        "bottom": 1400,
        "right": 1170
      },
      "boundsWithFX": {
        "top": 0,
        "left": -2,
        "bottom": 1400,
        "right": 1170
      },
      "visible": true,
      "clipped": false,
      "blendOptions": {
        "mode": "passThrough"
      },
      "generatorSettings": false
    }
  ]
}

And this is the response, for the second group ColorrWheel (contains both groups):

{
  "version": "1.6.1",
  "timeStamp": 0,
  "count": 0,
  "id": 59,
  "file": "U:\\Creative Cloud Files\\_Stuff\\ColorWheel.psd",
  "bounds": {
    "top": 0,
    "left": 0,
    "bottom": 1400,
    "right": 1168
  },
  "selection": [
    9
  ],
  "resolution": 72,
  "globalLight": {
    "angle": 90,
    "altitude": 30
  },
  "generatorSettings": false,
  "profile": "Untagged RGB",
  "mode": "RGBColor",
  "depth": 8,
  "layers": [
    {
      "id": 29,
      "index": 20,
      "type": "layerSection",
      "name": "ColorrWheel copy",
      "bounds": {
        "top": 0,
        "left": -2,
        "bottom": 1400,
        "right": 1170
      },
      "boundsWithFX": {
        "top": 0,
        "left": -2,
        "bottom": 1400,
        "right": 1170
      },
      "visible": false,
      "clipped": false,
      "blendOptions": {
        "mode": "passThrough"
      },
      "generatorSettings": false
    },
    {
      "id": 16,
      "index": 9,
      "type": "layerSection",
      "name": "ColorrWheel",
      "bounds": {
        "top": 0,
        "left": -2,
        "bottom": 1400,
        "right": 1170
      },
      "boundsWithFX": {
        "top": 0,
        "left": -2,
        "bottom": 1400,
        "right": 1170
      },
      "visible": true,
      "clipped": false,
      "blendOptions": {
        "mode": "passThrough"
      },
      "generatorSettings": false
    }
  ]
}