Skip to main content

figma.variables

These are all defined on figma.variables. Please see the Working with Variables guide for how to use these functions to interact with variables in Figma.

getVariableByIdAsync(id: string): Promise<Variable | null>

Finds a variable by ID. If not found or the provided ID is invalid, returns a promise containing null.

View more →


getVariableById(id: string): Variable | null

DEPRECATED: Use getVariableByIdAsync instead. This function will throw an exception if the plugin manifest contains "documentAccess": "dynamic-page".

Finds a variable by ID. If not found or the provided ID is invalid, returns null.

View more →


getVariableCollectionByIdAsync(id: string): Promise<VariableCollection | null>

Finds a variable collection by ID. If not found or the provided ID is invalid, returns a promise containing null.

View more →


getVariableCollectionById(id: string): VariableCollection | null

DEPRECATED: Use getVariableCollectionByIdAsync instead. This function will throw an exception if the plugin manifest contains "documentAccess": "dynamic-page".

Finds a variable collection by ID. If not found or the provided ID is invalid, returns null.

View more →


getLocalVariablesAsync(type?: VariableResolvedDataType): Promise<Variable[]>

Returns all local variables in the current file, optionally filtering by resolved type.

View more →


getLocalVariables(type?: VariableResolvedDataType): Variable[]

DEPRECATED: Use getLocalVariablesAsync instead. This function will throw an exception if the plugin manifest contains "documentAccess": "dynamic-page".

Returns all local variables in the current file, optionally filtering by resolved type.

View more →


getLocalVariableCollectionsAsync(): Promise<VariableCollection[]>

Returns all local variable collections in the current file.


getLocalVariableCollections(): VariableCollection[]

DEPRECATED: Use getLocalVariableCollectionsAsync instead. This function will throw an exception if the plugin manifest contains "documentAccess": "dynamic-page".

Returns all local variable collections in the current file.


createVariable(name: string, collection: VariableCollection, resolvedType: VariableResolvedDataType): Variable

Creates a variable with a given name and resolved type inside a collection.

View more →


createVariableCollection(name: string): VariableCollection

Creates a new variable collection with the given name.

View more →


createVariableAlias(variable: Variable): VariableAlias

Helper function to create a variable alias.

This should be used with functions such as node.setProperties() to assign component properties to variables.


createVariableAliasByIdAsync(variableId: string): Promise<VariableAlias>

Helper function to create a variable alias.

This should be used with functions such as node.setProperties() to assign component properties to variables.


setBoundVariableForPaint(paint: SolidPaint, field: VariableBindablePaintField, variable: Variable | null): SolidPaint

Helper function to bind a variable to a SolidPaint.

If null is provided as the variable, the given field will be unbound from any variables.


setBoundVariableForEffect(effect: Effect, field: VariableBindableEffectField, variable: Variable | null): Effect

Helper function to bind a variable to an Effect.

If null is provided as the variable, the given field will be unbound from any variables.


setBoundVariableForLayoutGrid(layoutGrid: LayoutGrid, field: VariableBindableLayoutGridField, variable: Variable | null): LayoutGrid

Helper function to bind a variable to a LayoutGrid.

If null is provided as the variable, the given field will be unbound from any variables.


importVariableByKeyAsync(key: string): Promise<Variable>

Loads a variable from the team library. Promise is rejected if there is no published variable with that key or if the request fails.

View more →