Hey guys,
I made a plugin that does this:
- get layer
- get its shared style
- getLibrary of that style
- based on the name of the style, find its "buddy" in the same library
- assign new style to the layer
It's easy with regular layers, but how do I do this with a symbol? When I try to do override.sharedStyle
I get always null. It only exposes sharedStyleId
.
I also tried to get the style by finding it in references, but I can't seem to get it. Check out what I've tried in playground
const doc = sketch.getSelectedDocument()
const selectedLayers = doc.selectedLayers
let Library = sketch.Library
let libraries = Library.getLibraries()
let textStyleReferences = []
for (let library of libraries) {
textStyleReferences = textStyleReferences.concat(library.getImportableTextStyleReferencesForDocument(doc))
}
let sharedStyleImportedId = selectedLayers.layers[0].overrides[1].value
let sharedStyleId = sharedStyleImportedId.substring(sharedStyleImportedId.search(/\[[A-Z|0-9|\-]*\]/) + 1, sharedStyleImportedId.length-1) //this isolates the layer ID
let sharedStyle = textStyleReferences.find(layerStyle => layerStyle.id == sharedStyleId)
console.log(sharedStyle) // I get null