Skip to content

Instantly share code, notes, and snippets.

@rogie
Last active March 4, 2023 15:09
Show Gist options
  • Select an option

  • Save rogie/e4fd3976e0cec49b6079d9624ddc7235 to your computer and use it in GitHub Desktop.

Select an option

Save rogie/e4fd3976e0cec49b6079d9624ddc7235 to your computer and use it in GitHub Desktop.
// SAVING some settings on a layer (code.ts/figma scene)
// Namespace
const dataNamespace = 'stipple-settings'
// get a node
let layer = figma.currentPage.selection[0]
// options to save in json format
let options = {
some: true,
settings: 1,
here: [1,2,3]
}
layer.setPluginData(dataNamespace, JSON.stringify(options))
// GETTING settings from a layer
figma.on("selectionchange", () => {
let selected = figma.currentPage.selection[0]
let settings = selected.getPluginData(dataNamespace)
if(settings){
settings = JSON.parse(settings)
} else {
//some default settings?
}
//post message to ui, passing the settings
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment