Sketch Gists — Useful snippets for plugin development

Sahil Dave
Aug 10, 2017 · 3 min read
Image for post
Image for post

Problem

If you use a text layer in a symbol, you can only override only the text; not any other property including font colour or weight.

Solution

Until Sketch releases an update where you override all the properties in a text layer it would be good to convert all your text styles into text symbols and use them in your other symbols.

Finding page, layer or symbol

  1. findPageByName the pages parameter can be fetched from the document by using doc.pages().
  2. findSymbolByName list of symbols can be obtained by, again, using the document. The getSymbols(doc) function looks like this.
/**
* Get all the symbols for a document.
* @param {MSDocument} doc
* @return {NSArray}
*/
function getSymbols(doc) {
return doc.documentData().allSymbols();
}

Creating Artboard, Page, TextLayer & Symbol

  1. There are two types of createPage functions. First creates a new page and adds it to the document data. Important step is to call doc.loadLayerListPanel() after you add the page, otherwise the page won’t appear on the left unless you collapse and expand the page list.
    The second function creates a blank page and renames it, as simple as that.
  2. Creating text layer also follows the same trend. One thing to remember is to add it to a page by page.addLayers([layer]); .
  3. Creating symbol from layer is a bit verbose. You take in a page, layer and the symbol name; add the layer to the page, convert the same layer to a new symbol, move this new symbol to the symbols page and remove the original symbol instance (which was added to the page).

Show symbols page, get all symbols, get last symbol



Design + Sketch

The best collection of articles, tips, tutorials, and…

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store