Introduction
The Common Layer Interface (CLI) describes a part as a stack of flat layers for machines that build layer by layer: resin curing, powder sintering or binding, sheet cutting and metal melting. Each layer holds the outlines of solid material and, optionally, hatch lines. Version 2.0 came out of the European Brite-EuRam projects “Rapid Prototyping Techniques” and “Phidias”.
A file is an ASCII header followed by the geometry, which is written either as ASCII commands or as binary records. The coordinate system is right-handed, layers are parallel to the xy plane and the part is built towards positive z.
ASCII syntax
A command is a keyword in upper case beginning $$, followed, if it has parameters, by
/ and the parameters separated by commas. The separators are /,
, and //. Only letters, digits, ., $ and the
separators are interpreted; other characters are ignored.
- Comment:
// text //. The text cannot contain//. - Integer: digits with an optional
+or-, within ±231. - Real: an optional sign and 1 to 16 digits with a decimal point, which is required.
- String: printable characters between double quotes, which the string cannot contain.
A file has a header section and a geometry section. Anything before $$HEADERSTART or after
$$GEOMETRYEND is ignored.
Header
The header runs from $$HEADERSTART to $$HEADEREND. The first three commands
after the markers in this table are listed by the specification ahead of the sentence that makes all
following header commands optional.
| Command | Meaning |
|---|---|
$$HEADERSTART | Starts the header, and the data. |
$$HEADEREND | Ends the header. |
$$BINARY or $$ASCII | Form of the geometry section. |
$$UNITS/u | Real. One coordinate unit is u millimetres. |
$$VERSION/v | Integer. The version is v ÷ 100, so 200 is 2.00. |
$$DATE/d | Integer read as DDMMYY, the date the file was built. |
$$DIMENSION/x1,y1,z1,x2,y2,z2 | Reals. The box that contains the part, in millimetres from the origin, with each first value below its second. |
$$LAYERS/i | Integer. Number of layers in the file. |
$$ALIGN | Binary files only: align geometry data to 32 bits (below). |
$$LABEL/id,text | Integer and string. Names the part with identifier id. There should be one for every identifier used by polylines and hatches; each identifier is built as a separate part. |
$$USERDATA/uid,len,data | Private data. uid is a string naming its owner; len is the number of bytes of data, counted from the byte after the comma that follows len up to the next $$ command. The data may be ASCII or binary. |
ASCII geometry
The section runs from $$GEOMETRYSTART to $$GEOMETRYEND, which also ends the
data.
| Command | Meaning |
|---|---|
$$LAYER/z | Starts a layer whose upper surface is at height z × units millimetres. |
$$POLYLINE/id,dir,n,p1x,p1y,…,pnx,pny | id and dir are integers, n the number of points, then n pairs of reals. |
$$HATCHES/id,n,p1sx,p1sy,p1ex,p1ey,… | n independent straight lines, each given by start x, start y, end x, end y: n × 4 reals. |
Layers
Layers must be in ascending order of z. A layer’s thickness is its z minus that of
the layer before it. To give the lowest layer a thickness, precede it with a “zero layer”: a
$$LAYER with no polylines.
Contours and orientation
| dir | Polyline | Direction, seen looking down the z axis |
|---|---|---|
| 0 | Internal contour (hole) | Clockwise |
| 1 | External contour | Counter-clockwise |
| 2 | Open line, not solid | Any |
A closed polyline (0 or 1) repeats its first point as its last. Contours must not cross themselves or each other. The order of points should agree with dir; where it does not, dir wins. Open lines and hatches are meant for supports and filling.
$$HEADERSTART
$$ASCII
$$UNITS/1.0
$$VERSION/200
$$LABEL/1,"plate"
$$LAYERS/2
$$HEADEREND
$$GEOMETRYSTART
$$LAYER/0.0
$$LAYER/0.1
$$POLYLINE/1,1,5,0.0,0.0,10.0,0.0,10.0,10.0,0.0,10.0,0.0,0.0
$$HATCHES/1,2,1.0,3.0,9.0,3.0,1.0,7.0,9.0,7.0
$$GEOMETRYEND
Binary geometry
A binary file keeps the ASCII header. The geometry starts on the byte directly after
$$HEADEREND, with no line break between, and ends the data; there are no geometry markers
and no non-geometric commands. A record is a command index followed by its parameters, with no
separators.
| Type | Size | Encoding |
|---|---|---|
| unsigned integer | 2 bytes | 0 to 65535. The command index has this type. |
| long integer | 4 bytes | Two’s complement. |
| real | 4 bytes | IEEE single precision. |
The most significant byte is at the highest address: values are little-endian.
| Index | Command | Parameters |
|---|---|---|
| 127 | Start layer, long | z: real. |
| 128 | Start layer, short | z: unsigned integer. |
| 129 | Start polyline, short | id, dir, n, then n × 2 coordinates: all unsigned integers. |
| 130 | Start polyline, long | id, dir, n: long integers; n × 2 coordinates: reals. |
| 131 | Start hatches, short | id, n, then n × 4 coordinates: all unsigned integers. |
| 132 | Start hatches, long | id, n: long integers; n × 4 coordinates: reals. |
The parameters mean what they do in ASCII, and all coordinates and heights are multiplied by the header’s units. Short coordinates are unsigned, so they cannot be negative.
Alignment
With $$ALIGN, the header ends at the end of a 32-bit word, the geometry starts at the
beginning of one, and every data item starts on a word boundary, leaving unused bytes after 2-byte
items. A coordinate pair counts as one item, so in the short polyline and hatch records an x and y
share one word.
24 24 48 45 41 44 45 52 53 54 41 52 54 0A … $$HEADERSTART, $$BINARY,
… $$UNITS/0.01, $$VERSION/200,
24 24 48 45 41 44 45 52 45 4E 44 $$HEADEREND
80 00 DC 05 128: layer at z = 1500 (15 mm)
81 00 00 00 01 00 04 00 129: id 0, external, 4 points
00 00 00 00 E8 03 00 00 00 00 E8 03 00 00 00 00
(0,0) (1000,0) (0,1000) (0,0)
Recognising a file
Data starts at $$HEADERSTART, which in practice opens the file, although the
specification allows other bytes before it. $$BINARY or $$ASCII in the
header says how to read the rest.
Divergence in specification and software
- The specification’s own ASCII example uses identifier 0 without a
$$LABELand has no$$VERSION, so readers should not insist on either. - Autodesk Netfabb states that its CLI export does not support negative coordinates and offers to move parts to the origin. It can write part names as labels and can leave out the empty layer at zero height.
- The colain library reads binary CLI and does not yet read the ASCII form.
In the explorer
The viewer follows the version 2.0 specification and reads ASCII files and binary files, plain or aligned to 32-bit words. Every header command is listed, including labels and user data with the medical items of the specification. Every geometry command, polyline point and hatch is listed. Polylines and hatches are drawn in 3D, each at the height of its layer and in parts of two million lines, and each layer opens as a picture.
Contours that are not closed or that run against their direction, layers that do not rise and counts that do not match are reported. Files up to 256 MB are read.
Links
Software
- Autodesk Netfabb – build preparation software that exports CLI slices (Windows)
Developers
- colain – parser for binary CLI files (Rust)
Reference
- Common Layer Interface, version 2.0 – copy of the specification first published at the University of Passau