ZSLICEDOCS

Embedding

Embedding zslice: overview

zslice is a library first. The command line tool is a small program on top of it. You can use the library from Zig, from C (or any language with a C foreign function interface), and from JavaScript through WebAssembly.

The objects

ObjectWhat it is
MeshThe triangles of the part, with welded vertices. Load it from STL bytes, or make it from a triangle list.
SettingsAll settings, in four groups: machine, filament, project, engine. Each has a default. Change a setting by its name and a text value.
StatsThe result of a slice: the layer count, the filament length and weight, the time estimate, the travel distance, and the retraction count.
Job (Zig only)A slice after its first pass. It has the outline of each layer. Use it to get the paths of one layer (for a preview) without the G-code.

The flow

  1. Load the mesh.
  2. Make the settings and change the ones you need.
  3. Slice. The G-code goes to your writer (Zig), to your callback (C), or into one buffer.
  4. Free the mesh and the settings.

The library does not read or write files. Your program gives it bytes and gets bytes back. Thus the same API works in a browser, on a server, and on a printer controller.

Setting names

A setting name is group.name, for example project.wall_count. The value is always text: "3", "0.2", "true", "grid". The library parses it to the type of the setting. To list all names:

The settings reference has the meaning, unit, and default of each setting.

Memory

Threads

Errors

Each failure has a name. In Zig, it is an error value. In C, it is a status code. In JavaScript, it is a ZsliceError with a status field.

Zig errorC statusMeaning
error.OutOfMemoryZS_OUT_OF_MEMORY (1)The allocator has no more memory.
ZS_INVALID_ARGUMENT (2)A required pointer is NULL (C only).
error.InvalidStlZS_INVALID_MESH (3)The bytes are not a valid STL file.
error.EmptyMeshZS_EMPTY_MESH (4)No triangles, or no height.
error.UnknownSettingZS_UNKNOWN_SETTING (5)The setting name does not exist.
error.InvalidValueZS_INVALID_VALUE (6)The value text cannot be parsed to the setting type.
error.InvalidSettingsZS_INVALID_SETTINGS (7)The values together cannot make a print.
error.PartTooLargeZS_PART_TOO_LARGE (8)The part is higher than machine.max_height.
error.WriteFailedZS_WRITE_FAILED (9)The writer failed, or the C callback returned a value that is not 0.

Stability

zslice is at version 0.1. The API can change before version 1.0. Setting names can also change. The change log will list each change.

The language guides