5 With Style Now
If you look closely you can see the layer's style properties. You might have been able to guess that to get at a layer's style you could do this:
console.log(selection.layers[0].style)
Style {
type: 'Style',
id: '9F025CC5-3A21-4F6C-BEAF-F12C707C7612',
opacity: 1,
blendingMode: 'Normal',
borderOptions:
BorderOptions {
startArrowhead: 'None',
endArrowhead: 'None',
dashPattern: [],
lineEnd: 'Butt',
lineJoin: 'Miter' },
blur:
Blur {
center: { x: 0.5, y: 0.5 },
motionAngle: 0,
radius: 10,
enabled: false,
blurType: 'Gaussian' },
fills:
[ Fill {
fillType: 'Color',
color: '#d8d8d8ff',
gradient: [Gradient],
pattern: [Object],
enabled: true } ],
borders:
[ Border {
fillType: 'Color',
position: 'Inside',
color: '#979797ff',
gradient: [Gradient],
thickness: 1,
enabled: true } ],
shadows: [ ],
innerShadows: [ ],
styleType: 'Layer',
fontAxes: null }
Going along with the same pattern you can probably guess that to get at a layer's fills you can get to it like this:
console.log(selection.layers[0].style.fills)
[ Fill {
fillType: 'Color',
color: '#d8d8d8ff',
gradient:
Gradient {
gradientType: 'Linear',
from: [Object],
to: [Object],
aspectRatio: 0,
stops: [Array] },
pattern: { patternType: 'Fill', image: null, tileScale: 1 },
enabled: true } ]
Which is an array of Fill
objects. Now we can get at the color!
console.log(selection.layers[0].style.fills[0].color)
'#d8d8d8ff'
Changing the color
If we try setting this property with a hex value you'll see that the color of the selected layer does indeed change!
selection.layers[0].style.fills[0].color = '#FF0000'
console.log(selection.layers[0].style.fills[0].color)
'#ff0000ff'