0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Very useful Figma API & plugins

Last updated at Posted at 2023-06-23

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

  1. download scripter plugin https://www.figma.com/community/plugin/757836922707087381/scripter

  2. 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:

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?