Did you know you can access the Figma plugin API without having to write a Figma plugin? Using the console inside Figma can help you speed up your workflow and is a great way to get started with the plugin API.
These are a collection of snippets I’ve found helpful when I’m creating and maintaining components in Figma libraries. I hope you find them handy too!
<aside> 💡 Before running a script, create a checkpoint in your Figma file’s version history so that you’re able to restore your file if you make a mistake.
</aside>
Select layers of a particular name, within a selection
let layerName = "Change This"
let newSelection = []
figma.currentPage.selection.map(layer => {(layer.name === layerName ? newSelection.push(layer) : null)})
figma.currentPage.selection = newSelection
Hide selected layers of a particular name
let layerName = "Change This"
figma.currentPage.selection.map(layer => {(layer.name === layerName ? layer.visible = false : null)})
Delete selected layers of a particular name
let layerName = "Change This"
figma.currentPage.selection.map(layer => {(layer.name === layerName ? layer.remove() : null)})
Delete hidden layers within a selection
figma.currentPage.selection.map(layer => {(layer.visible === false ? layer.remove() : null)})