Last active
March 14, 2021 08:19
-
-
Save kemiljk/318dab306e872da068f3cacdf0bef16f to your computer and use it in GitHub Desktop.
A way to add a title to all Frames and apply common export settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOTE: This uses the Scripter API so won't work as a normal Figma plugin | |
// Download here: https://www.figma.com/community/plugin/757836922707087381/Scripter | |
const layers = figma.currentPage.findAll(); | |
const frames = layers.filter(isFrame); | |
async function renameFrames() { | |
let items = frames; | |
if (items.length > 0) { | |
for (const node of items) { | |
if (node.type === "FRAME") { | |
node.name = ((node.name).substr(0,2) != 'Slide/') ? node.name = "Slide" + "/" + node.name : node.name; | |
} | |
} | |
} | |
} | |
renameFrames(); | |
figma.currentPage.selection = layers.filter((n) => n.name.startsWith("Slide/")); | |
const { selection } = figma.currentPage; | |
function hasValidSelection(nodes) { | |
return !(!nodes || nodes.length === 0); | |
} | |
const settings = [ | |
{ format: "PNG", suffix: "@1x", constraint: { type: "SCALE", value: 1 } }, | |
{ format: "PNG", suffix: "@2x", constraint: { type: "SCALE", value: 2 } }, | |
{ format: "PNG", suffix: "@3x", constraint: { type: "SCALE", value: 3 } }, | |
{ format: "SVG", suffix: "" }, | |
]; | |
async function main(nodes): Promise<string> { | |
if (!hasValidSelection(nodes)) return Promise.resolve("No valid selection"); | |
for (let node of nodes) { | |
node.exportSettings = settings; | |
} | |
return Promise.resolve("Done!"); | |
} | |
main(selection).then((res) => figma.closePlugin(res)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment