Global Objects
You can access most of the Plugin API through the figma global object. You'll find properties and functions that allow you to view, create, and update the contents of files.
- View and update file-level properties, like thumbnails, undo history, and version history
- Create, copy, or combine layers
- Adjust properties of existing layers
- Create, use, and manage local styles
- Access users in the file
- Import styles and component from external libraries
Example:
figma.createRectangle()
figma.closePlugin()
Tip: The figma global object is available in every Figma window. This means you can open the developer console in any file and access the API. This is a great way to explore the functionality of the API without having to create a plugin. You can also use this approach to test and debug your plugin code.
There are several other global objects available. You can access these from methods on the figma global object:
figma.uito create a custom interface for your pluginfigma.codegento implement code generation in Dev Modefigma.timerto control the timer object in FigJam filesfigma.viewportto control the viewport: the area of the canvas that's visible on screenfigma.clientStorageto store data on a user's local machinefigma.parametersto accept parameters as inputfigma.variablesto interact with variablesfigma.teamLibraryto interact with assets in a team libraryfigma.textreviewto interact with features only available to text review plugins
There are also global variables available across the Plugin API:
html
If you assigned a file name to the "ui" field in your manifest.json file, you can use this variable to access the file's contents.
Instead of including HTML within a JavaScript string, you can call figma.showUI(__html__) . As the HTML is in a separate file, your text editor will render the HTML with syntax highlighting.
uiFiles
If you assigned a map to the "ui" field in your manifest.json file:
"ui": {
"main": "main.html",
"secondary": "secondary.html"
}
you can use this variable to access each file's contents. You can then call figma.showUI(__uiFiles__.main).
fetch(url: string, init?: FetchOptions): Promise<FetchResponse>
Fetch a resource from the network, and return a promise with the response.