How to
Go to Specific Layers

Go to specific layers

This is a pretty cool feature, especially if you have a large design document, and/or need to focus on sections of a design.

Figma gives you an easy way to bring layer(s) into view.

Here is an example of going to one layer:

code.js
// let's grab a layer node by it's ID
const layerNode = figma.getNodeById('123:456');
 
// prevent a figma memory leak (if not found, can't be focused)
if (layerNode !== null) {
  // bring layer into view
  figma.viewport.scrollAndZoomIntoView([layerNode]);
  // NOTICE: make sure to pass as an array, ^ wrapping with []
}

Let's say we want to focus on multiple layers and set them as selected, here's how you would do that:

code.js
// passing in multiple layer id's
const layersToBringIntoView = ['123:456', '789:123', '456:789'];
 
// get all layer nodes by id
const zoomToNodes = layersToBringIntoView.map((id) => figma.getNodeById(id));
 
// bring all layers into view
figma.viewport.scrollAndZoomIntoView(zoomToNodes);
 
// select them in Figma document
figma.currentPage.selection = zoomToNodes;

Check Figma API Docs for all Zoom into View (opens in a new tab) options.