Ah sorry I did look into the issue but forgot to report back here:
I'm running Sketch 71
let sketch = require('sketch')
let doc = sketch.getSelectedDocument()
// let docSwatches = doc.swatches
// Can't do this ^
doc.swatches = []
let mySwatch = sketch.Swatch.from({
name: 'Safety Orange',
color: '#ff6600'
})
doc.swatches.push(mySwatch)
let selectedLayer = doc.selectedLayers.layers[0]
selectedLayer.style.fills[0].color = mySwatch.referencingColor
I previously recommended that you could reference docSwatches
the variable and then mutate that around however that's just an instance and you need to directly mutate doc.swatches
.
As to @ziyafenn 's issue. You can't directly pass the referencing color into the fills parameter that way. You'll need to be explicit in assigning it to the color property.
let sketch = require('sketch')
let doc = sketch.getSelectedDocument()
let ShapePath = sketch.ShapePath
let selectedLayer = doc.selectedLayers.layers[0]
doc.swatches = []
let mySwatch = sketch.Swatch.from({
name: 'Safety Orange',
color: '#ff6600'
})
doc.swatches.push(mySwatch)
selectedLayer.style.fills[0].color = mySwatch.referencingColor
let newLayer = new ShapePath({
parent: selectedLayer.parent,
frame: { x: 0, y:0, width: 100, height: 100 },
style: { fills: [{color: mySwatch.referencingColor}] }
})
I'm not able to reproduce the issue where the assigned color isn't actually linked to the variable.