Plugin
Scripter: Speed up your workflow or experiment with the Figma API through scripts.
Google Sheets Sync: Sync content from Google Sheets directly into your Figma file
Node Inspector: View and copy node properties for plugin development.
API
// get node text content
const title = figma.getNodeById("1:121")
console.log(title.characters)
// set node text content
title.characters = "abc"
// fetch image from url
figma.createImageAsync(
'https://picsum.photos/200'
).then(async (image: Image) => {
const imgnode = figma.getNodeById("1:11")
// Resize the node to match the image's width and height
const { width, height } = await image.getSizeAsync()
imgnode.resize(width, height)
// Set the fill on the node
imgnode.fills = [{
type: 'IMAGE',
imageHash: image.hash,
scaleMode: 'FILL'
}
]
}).catch((error: any) => {
console.log(error)
})
////////////////////////////////////
// Create an instance from the component
const template = figma.getNodeById("1:123")
let ins = template.createInstance()
// get ins children
let person = ins.children[8]
// create style
let styleName = `chinese_tradition_color/${color.name}`
let style = figma.createPaintStyle()
style.name = styleName
style.paints = [{
blendMode: "NORMAL",
color: [251, 164, 20], // 淡橘橙
opacity: 1,
type: "SOLID",
visible: true,
}, ]
ins.fillStyleId = style.id
batch create invites
-
download scripter plugin https://www.figma.com/community/plugin/757836922707087381/scripter
-
Enter the following
function createPost(template, items) {
let arr = []
for (const item of items) {
let ins = template.createInstance()
let person = ins.findOne((n => n.name === "#name"))
ins.name = item.name
person.characters = item.name
arr.push(ins)
}
return arr
}
const list = [{
name: "shooter",
},
{
name: "tiny",
},
{
name: "bob",
},
{
name: "alice",
}
]
const component = figma.currentPage.findOne((n => n.name === "#Poster"))
const posts = createPost(component, list)
Ref: