.MOD File Format

KiCad legacy footprint library

Introduction

A legacy footprint library of KiCad, the electronics design suite, is a text file that holds any number of footprints: the copper pads, outlines and labels that a component occupies on a circuit board. It carries the extension .mod, or .emp, and starts with the words PCBNEW-LibModule-V1.

The newer .kicad_mod footprint is a different format, written as S-expressions with one footprint to a file. Many unrelated formats also use .mod; the first line tells this one apart.

There is no specification here to follow. This page describes what the legacy reader of KiCad 10.0 accepts, with details of what was written taken from the library writer kept, switched off, in the source of KiCad 4.0.0. Footprints are written as in the legacy board file, so their lines are described there.

Layout of the file

PartContents
PCBNEW-LibModule-V1First line, which may go on with other words, such as a date
Header linesAmong them Units mm, if the lengths are in millimetres
$INDEX … $EndINDEXList of footprint names
$MODULE name … $EndMODULEOne footprint; repeated
$EndLIBRARYLast line as 4.0.0 wrote it
PCBNEW-LibModule-V1  2013-01-01 00:00:00
# encoding utf-8
Units mm
$INDEX
R_example
$EndINDEX
$MODULE R_example
Po 0 0 0 15 00000000 00000000 ~~
Li R_example
Cd Two-pad example part
Kw resistor
Sc 00000000
Op 0 0 0
At SMD
T0 0 -1.6 1 1 0 0.15 N V 21 N "R**"
T1 0 1.6 1 1 0 0.15 N V 21 N "R_example"
DS -0.4 -0.9 0.4 -0.9 0.15 21
DS -0.4 0.9 0.4 0.9 0.15 21
$PAD
Sh "1" R 1 1.3 0 0 0
Dr 0 0 0
At SMD N 00888000
Ne 0 ""
Po -0.95 0
$EndPAD
$PAD
Sh "2" R 1 1.3 0 0 0
Dr 0 0 0
At SMD N 00888000
Ne 0 ""
Po 0.95 0
$EndPAD
$EndMODULE R_example
$EndLIBRARY
A library with one surface mount footprint, made up for this page, in millimetres.

The index

  • Between $INDEX and $EndINDEX stands one footprint name to a line. The writer in 4.0.0 lists them in sorted order and then writes the footprints in the same order.
  • KiCad 10.0 does not use the names: it skips the whole section and finds footprints by their own $MODULE lines.
  • Some libraries have several index sections one directly after another, left by a fault in older programs. All of them are skipped.
  • A file with no $INDEX line, or with an index that never ends, gives no footprints in KiCad 10.0, without an error. KiCad 4.0.0 reports a file with no $INDEX as empty or not a legacy library.

Footprints and their names

  • After the index, each line that starts with the keyword $MODULE opens a footprint. Other lines between footprints are passed over, so $EndLIBRARY is not required and does not stop the reading.
  • A footprint must close with a line starting $EndMODULE; the end of the file inside a footprint is an error. 4.0.0 repeats the name after the keyword.
  • The name is the rest of the $MODULE line, with white space trimmed from both ends.
  • In the name, each of \ / : " < > | * ? is replaced by % and the two hexadecimal digits of the character, so / becomes %2f.
  • Names are compared with regard to case. When one occurs again, the later footprint is kept under the name with _v2 added, or _v3 and so on, the first that is free.

Inside a footprint

KiCad reads a library footprint with the same code as a footprint on a legacy board.

LinesDescribed under
Po, Sc, Li, Cd, Kw, At, AR, Op and the lines starting with .Footprints
T0, T1 and further T linesFootprint text
DS, DC, DA, DP with its Dl linesFootprint graphics
$PAD … $EndPADPads
$SHAPE3D … $EndSHAPE3D3D models
Layer numbers and masksLayers

Differences in a library

  • The unit comes from the library header and applies to every footprint. The three numbers of a 3D model’s scale, offset and rotation are not converted.
  • No line states the number of copper layers, and the reader assumes 16. Layer 15 is the front copper, 0 the back, and an inner layer numbered n from 1 to 14 becomes inner layer 15 − n counted from the front.
  • Pad names are read as UTF-8.
  • A library has no net table. The reader takes the code of a pad’s Ne line as it stands and makes no use of the name.
  • The position and rotation on the Po line also place the graphics that follow it, as on a board, so the line comes before them.

What KiCad 4.0.0 wrote

The library writer in the 4.0.0 source is compiled out, but shows the order of a footprint: $MODULE, Po, Li, then Cd and Kw if not empty, Sc, AR, Op, any . lines and At that differ from the default, the reference and value texts, further texts and graphics, pads, 3D models that name a file, and $EndMODULE with the name.

KiCad 10.0 reads these libraries but has no way to save a footprint into one. It can delete the library file.

Recognising and reading the file

  • To recognise a library, KiCad requires the extension .mod or .emp, in any case. Leaving out leading spaces and tabs, blank lines and lines starting #, the first line must then begin with PCBNEW-LibModule-V and a later one with $MODULE, both in any case.
  • Loading is stricter: the header must be on the very first line and give version 1, and a $MODULE keyword must stand at the start of its line.
  • The whole library is read at once and kept in memory, and read again when the file’s modification time changes.
  • If an error stops the reading, the footprints completed before it can still be listed.

In the explorer

A dropped .mod or .emp library shows its index and footprints as a byte tree and a drawing of one footprint, chosen in the options, with its pads, graphics and texts at the footprint’s own origin without its stored rotation. Options also choose the layers and the size of the picture. A click in the picture selects the bytes of the item. Tables list every footprint, name in the index, pad, text, graphic, 3D model location and header line.

A tracker music file or a Go module file with the extension .mod is told apart by its contents.

Files up to 400 MB are read; in a library of more than 4,096 footprints the one to draw is chosen by its row number.

Not described

Known, not yet covered

  • Viewer, text: text is drawn in the site’s own stick font, not KiCad’s, with ASCII, accented Latin letters and some common signs; other characters are not drawn as themselves.
  • Viewer, local settings: solder mask and paste clearances are listed but not applied to the drawing.

Also used for

Links

Software

  • KiCad – free electronics design suite that reads legacy footprint libraries (Windows, macOS, Linux)

Developers

Reference