Skip to content

Instantly share code, notes, and snippets.

View thomas-lowry's full-sized avatar

Tom Lowry thomas-lowry

  • Toronto, ON
View GitHub Profile
@thomas-lowry
thomas-lowry / selectTopLevelFrames
Created December 9, 2019 17:21
Selects all top level frames on a page
const frames = Array.from(figma.currentPage.findAll(item => item.type === 'FRAME' && item.parent.type === 'PAGE'));
figma.currentPage.selection = frames;
@thomas-lowry
thomas-lowry / ungroup-groups-with-one-child
Created October 17, 2019 18:53
Ungroup groups with one child in Figma
var groupsWithOneChild = Array.from(figma.root.findAll(x => x.type === 'GROUP' && x.children.length === 1));
if (groupsWithOneChild) {
groupsWithOneChild.forEach(group => {
let parent = group.parent;
let index = parent.children.indexOf(group);
let child = group.children[0];
parent.insertChild(index, child);
})
}
@thomas-lowry
thomas-lowry / hex values from Figma styles
Last active June 3, 2020 10:53
generate an array of hex values (and their style names) from Figma styles
const colorStyles = figma.getLocalPaintStyles();
var hexValueAndName = []; // array of hex values and their names
var hexValues = []; //array with hex values only
function makeHex(r,g,b) {
let red = rgbToHex(r);
let green = rgbToHex(g);
let blue = rgbToHex(b);
return red+green+blue;
}
@thomas-lowry
thomas-lowry / selectInstancesFromLibrary
Created September 16, 2019 13:44
Select all instances that come from a library on a Figma page
figma.currentPage.findAll(i => i.type === 'INSTANCES' && i.masterComponent.remote === true)
@thomas-lowry
thomas-lowry / getPage
Created September 14, 2019 16:30
Find the page of a node in Figma
function getPage(node) {
let item = node;
while (item.type != 'PAGE') {
item = item.parent;
console.log(item);
}
return item;
}