.KICAD_WKS File Format

KiCad drawing sheet

Introduction

A .kicad_wks file is a KiCad drawing sheet: the frame, reference marks and title block drawn behind a schematic or a board. It is S-expression text, used from KiCad 6.0 on, and is edited in KiCad's drawing sheet editor. A project file names the sheet it uses in page_layout_descr_file (one entry for the schematics, one for the board); without one KiCad draws its own default sheet. The file does not say what paper it is drawn on: that comes from the schematic or board using it.

Text syntax

Lists in parentheses, each beginning with a keyword, followed by values and further lists. Text with spaces or special characters is in double quotes, with \ escapes. Numbers are millimetres; KiCad's resolution here is one micrometre (three decimal places, anything finer being cut off). The file is UTF-8.

File structure

(kicad_wks (version 20231118) (generator "pl_editor") (generator_version "10.0")
  (setup (textsize 1.5 1.5) (linewidth 0.15) (textlinewidth 0.15)
         (left_margin 10) (right_margin 10) (top_margin 10) (bottom_margin 10))
  (rect (name "") (start 110 34) (end 2 2) (comment "title block"))
  (line (name "") (start 50 2 ltcorner) (end 50 0 ltcorner) (repeat 30) (incrx 50))
  (tbtext "1" (name "") (pos 25 1 ltcorner) (font (size 1.3 1.3)) (repeat 100) (incrx 50))
  (tbtext "Title: ${TITLE}" (name "") (pos 109 10.7) (font (size 2 2) bold italic))
)

The first word is kicad_wks or drawing_sheet, either followed at once by (version N). A file beginning (page_layout is of the form before versions and counts as version 0. After the header the only lists allowed are generator, generator_version, setup, line, rect, polygon, bitmap and tbtext, in any order; anything else is an error, as is a version later than the program's own. Items are drawn in the order written. Other programs writing such files should not give pl_editor as the generator.

Setup

ListMeaning
(textsize W H)Width and height of text that states none
(linewidth W)Width of lines that state none, or 0
(textlinewidth W)Pen width of text that states none, or 0
(left_margin D), (right_margin D), (top_margin D), (bottom_margin D)Distances from the paper's edges to the area the corners are taken from

The list may be empty. KiCad's own default sheet sets 1.5 × 1.5, 0.15, 0.15 and margins of 10.

Coordinates and corners

A point is X Y [CORNER]. X and Y are measured from a corner of the area inside the margins, positive towards the middle of the page: with the right bottom corner, X goes left and Y goes up.

WordCornerX growsY grows
rbcorner (also when no word is written)right bottomleftup
rtcornerright topleftdown
lbcornerleft bottomrightup
ltcornerleft toprightdown

The two ends of a line or rectangle each have their own corner, which is how a frame stretches with the paper.

Items

Lists shared by all items

ListMeaning
(name "…")A name for the item, shown in the editor
(comment "…")A remark, not drawn
(option page1only) or (option notonpage1)Drawn on the first page only, or on every page but the first. Without it the item is on all pages.
(repeat N)The number of copies, counting the first. A value below 1 is taken as 1, above 100 as 100.
(incrx D), (incry D)How far each copy is from the one before, in the directions of the item's corner

The first copy is always drawn, wherever it lies. A later copy is left out when it is outside the area inside the margins, widened to take in the first copy. For lines and rectangles both ends are tested, for polygons the box around their turned points, for texts and bitmaps the position.

line and rect

(start X Y [CORNER]), (end X Y [CORNER]) and (linewidth W). A rectangle is the outline with these as opposite corners; it is not filled.

polygon

Filled shapes. (pos X Y [CORNER]) places them; each (pts (xy X Y) …) is one contour, its points relative to the position with X to the right and Y down, whatever the corner. There may be several contours. The developer documentation asks for at least two points in a list; the program's reader does not check the number, and a contour of fewer than three points has no area to fill. (rotate DEGREES) turns the contours about the position, positive anticlockwise, and (linewidth W) states a line width, 0 when absent (the setup's line width is not taken). On screen KiCad 10.0 only fills the contours and does not use the width. When printing, it fills them and strokes each, closed, with the item's width or the program's default pen width, whichever is wider.

bitmap

A picture centred on (pos X Y [CORNER]). (scale S) multiplies its natural size, which follows from its pixel count and the resolution it states (300 pixels per inch if none). Since version 20230607 the image file is in (data "…" "…") as base64 text split over several strings. Older files have (pngdata (data "89 50 4E 47 …") (data "…") …): the bytes in hexadecimal, up to 32 to a line. A linewidth list is accepted too. An image that cannot be read is an error.

tbtext

(tbtext "TEXT" …) with (pos X Y [CORNER]) and these:

ListMeaning
(font …)(face "NAME") an outline font family (without it KiCad's stroke font); (size W H), 0 or none meaning the setup's size; bold; italic; (color R G B A) with red, green and blue 0 to 255 and opacity 0 to 1, opacity 0 meaning the sheet's usual colour; (linewidth W) the pen
(justify …)left, right, top, bottom, center (centred both ways). Without it the position is at the left end, half way up.
(rotate DEGREES)Turn of the text, anticlockwise
(maxlen D), (maxheight D)Largest width and height. A text whose box, rounded to whole millimetres, is wider or taller has its character width or height reduced in proportion. 0 means no limit.
(incrlabel N)The step of the label in repeated copies (default 1, may be negative)

In a repeated text of one line, the last number or run of letters is stepped by incrlabel from copy to copy: 1, 2, 3 … or A, B … Z, AA. Letters keep their case, and I, O, S, Q, X and Z are not skipped. In the text, the two characters \n begin a new line and \\ is one backslash.

Text variables

Texts may hold ${NAME}, filled in from the drawing being shown: TITLE, ISSUE_DATE, REVISION, COMPANY, COMMENT1 to COMMENT9, PAPER, # (page number), ## (page count), FILENAME, SHEETPATH, LAYER, KICAD_VERSION, the project's own text variables and others of the program; @{…} is an expression. See the schematic format.

Older title blocks used codes with a percent sign. KiCad converts them when it reads a text of any version:

CodeBecomesCodeBecomes
%%%%S${#}
%D${ISSUE_DATE}%N${##}
%R${REVISION}%F${FILENAME}
%K${KICAD_VERSION}%L${LAYER}
%Z${PAPER}%P${SHEETPATH}
%Y${COMPANY}%C0 to %C8${COMMENT1} to ${COMMENT9}
%T${TITLE}any otherremoved

File versions

VersionChange
0The page_layout form
20210606First numbered version. In older texts a single ~ switched an overbar on and off; it is converted to ~{…}.
20220228Fonts
20230607Images saved as base64
20231118Generator version; tidying of the format

Divergence from spec

KiCad's developer documentation of this format leaves out some of what the program reads: the first words drawing_sheet and page_layout; generator_version; option; a font's face, color and linewidth; justify, rotate, maxlen, maxheight and incrlabel of a text; several contours in one polygon; the base64 data of a bitmap (only the hexadecimal pngdata is shown there); the limit of 100 copies; and the percent codes. These are described above from the program.

Reading the file

  • A bold text is drawn with a pen a fifth of the smaller character dimension, whatever width is stated; no text pen is more than a quarter of it.
  • Choose the paper first: positions from the right and bottom depend on it.
  • Page 1 and later pages can differ, through option.
  • Integers outside a stated range, such as colour parts and the repeat count, are brought to the nearest limit rather than refused.

In the explorer

The explorer draws the sheet on a chosen paper (A5 to A0, A to E, the US sizes or a size you type, either way up; A4 landscape at first), as the first or a later page, with text variables as written or, by option, filled where a value is known: paper, page number, date, and the project name and text variables of a .kicad_pro file in the folder. Lines, rectangles, polygons, texts and bitmaps are drawn with their repeats and label steps, and listed in tables whose rows lead to their lists in the file. A bitmap's row opens the picture file the sheet holds. Polygons are drawn filled, as KiCad shows them, or by option stroked as well, as it prints them (the setup's line width standing in for the program's default pen). Text in KiCad's own font is drawn in the site's stick font, which has ASCII, accented Latin letters and some signs. A text that names an outline font is drawn in it when the font file (TrueType, OpenType or a collection) is in the folder; the named instances of a variable font count as faces under their instance names. Files up to 400 MB are read, with up to 400 MB of font files. A sheet that makes more than 200,000 shapes is drawn in parts of that many, chosen in the options.

Not described

Known, not yet covered

  • Viewer: characters outside the stick font's set show as boxes; fonts installed on your computer cannot be read by a page; variables that come from a schematic or board (title, revision and so on) stay as written; the page count is not known.

Links

Software

  • KiCad – free electronics design suite (Windows, macOS, Linux)

Developers

  • KiCad source code – the drawing sheet reader is in common/drawing_sheet (C++, GPL)

Reference