Prev Up Next
User Interface Developer's Guide

File Format

Sketch stores drawings in plain ASCII files using a line oriented format. The main idea is that each line of an sk file looks like a Python function call. Originally, this was just for convenience, as the import filter just had to define all those functions in a dictionary, and read and (r)eval each line.

That turned out to be quite slow, probably because each line is compiled to bytecode and then executed just once. Sketch now uses a parser written in C. This is much faster and doesn't have the potential security problems of eval.

All function arguments are Python literals, ints, floats, strings (delimited with single- or double-quotes, the usual \ escapes are allowed, but no triple quoted strings or raw strings), tuples and lists. Keyword arguments are also allowed.

Boolean values are represented as the ints 0 or 1.

Colors are represented by float triples describing the RGB values, each in the range 0..1 (e.g. red (1.0, 0.0, 0.0)).

All sk files start with '##Sketch' followed by two numbers, the major and minor version number of the file format.

Lines starting with # are comments, empty lines are ignored.

Overall structure

The first function in an sk-file is always 'document()'. This function takes no parameters.

The next part defines global parameters like the page layout and objects like styles.

After this follow the layers from bottom to top.


Functions for global parameters:

layout(format, orientation)

format is either the name of a predefined paper-format or a tuple (width, height) in pt. See Sketch/Lib/ for a list of predefined paper-formats.

orientation is 0 for portrait or 1 for landscape.


Define the style named name (a string). The preceding functions define the properties of this style. See the section on properties for details.


There are three kinds of layers, normal layers, grid layers and guide layers.

Normal layers and guide layers can contain other objects. All objects defined after a layer function are part of that layer. A layer is implicitly closed by another layer function or the end of file.

The layer functions:

layer(name, visible, printable, locked, outlined, outline_color)

Start a normal layer named name (a string). The booleans visible,printable, locked and outlined determine whether the layer is visible, printable, locked or only shown outlined.

outline_color defines the color used for the outlines of the objects in the layer.


Define the grid-layer. The geometry is a tuple of the form (xorig, yorig, xwidth, ywidth)

guidelayer(name, visible, printable, locked, outlined, outline_color)

Start the guide layer. The arguments are the same as for the normal layer, but the arguments printable and outlined will be ignored and set to 0 and 1 respectively.




Compound Objects


User Interface Developer's Guide
Prev Up Next