Skip to content

Instantly share code, notes, and snippets.

@sonburn
Created November 18, 2022 17:20
Show Gist options
  • Save sonburn/b6e64279700dbd57e8e086c63125c6a5 to your computer and use it in GitHub Desktop.
Save sonburn/b6e64279700dbd57e8e086c63125c6a5 to your computer and use it in GitHub Desktop.
Select symbol instance layers by name
const sketch = require("sketch")
const util = require("util")
const document = sketch.getSelectedDocument()
const documentData = document.sketchObject.documentData()
const selections = document.selectedLayers
const selection = selections.layers[0]
let layerName = 'Oval'
let instanceOverrides = util.toArray(selection.sketchObject.overrideContainer().flattenedChildren())
let uniqueOverrides = []
instanceOverrides.forEach(o => {
let overrideMatch = uniqueOverrides.find(u => u.availableOverride().overridePoint().path() == o.availableOverride().overridePoint().path())
if (!overrideMatch) uniqueOverrides.push(o)
})
let selectOverrides = uniqueOverrides.filter(o => String(o.availableOverride().affectedLayer().name()) == layerName)
documentData.setSelectedOverrides(selectOverrides.map(o => o.selectionID()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment