I am working with extracting data from Layers and then attempting to clone the Layer later on. One thing I've noticed is that Layers can have a multiple Fill types, and a Blending Mode can be set on each Fill.
My problem is that when I call API functions to retrieve this data, there doesn't seem to be any data in relation to Blending Modes other than on the top level of the Style object for each layer.
What I can do is call Internal API functions to access this, but it requires additional computation I am trying to avoid.
This can be achieved by calling sketchObject on a layer's style object, then calling appropriate methods to get/set the Blending Mode.
Say I have a single layer (a ShapePath) that I have selected, and I want to retrieve its data.
// Retrieving currently selected layers from the selected document
var selectedLayers = document.selectedLayers;
// Retrieving my ShapePath, the only layer selected
var layer = selectedLayers.layers;
Say this ShapePath has a single Fill with a Blending Mode other than Normal set on it. Not a blending mode on the Layer itself, but one that was added onto the actual Fill. I can get and set it by doing the following.
/** Retrieving Blending Mode - comes back as a number (Normal = 0) **/
const blendingMode = layer.style.sketchObject.fills().contextSettings().blendMode();
/** Setting Blending Mode - must set as number, 13 by default should be **Saturation** (at least on my machine and version) **/
This will work to retrieve and set that data, but I would like to know if anyone knows a better way to do this, or if I am missing something with the JS API.
Also, if this is the only way to do this, does anyone know why the JS API doesn't support Fill Blending Modes or is it something that may potentially be added in the future?
Thanks, any information would be greatly appreciated!