Introduction
UFP is the print file of UltiMaker printers as
UltiMaker Cura writes it. Instead of a bare
G-code file it is a package: the G-code together with a
picture of the model, the profiles of the materials it was sliced for and the slicer’s
settings. UltiMaker’s libCharon library, under the LGPL, reads and writes it, and registers the
media type application/x-ufp.
Structure
A UFP file is a ZIP archive laid out after the Open Packaging Conventions (OPC), the packaging also used by 3MF: a content types part names the media type of each file extension, and relationship parts say what each file is for. libCharon deflates the entries and streams them with ZIP64 records.
/[Content_Types].xml
/_rels/.rels
/3D/model.gcode
/3D/_rels/model.gcode.rels
/Metadata/thumbnail.png
/Metadata/UFP_Global.json
/Materials/name.xml.fdm_material
/Cura/slicemetadata.json
The entry names in the archive begin with a slash, as shown. That is what libCharon stores and what its readers, and others, ask for.
Parts
| Part | Contents |
|---|---|
/3D/model.gcode | The G-code to print, as UTF-8 text. This is the part every reader needs. |
/Metadata/thumbnail.png | A PNG picture of the sliced scene. Cura leaves it out when it has no snapshot. |
/Materials/name.xml.fdm_material | The XML material profile of each different material used by an extruder, named after the material’s base profile. The profile is a separate XML format, with root element fdmmaterial in the namespace http://www.ultimaker.com/material; Cura reads and writes it with its XmlMaterialProfile plugin, and UltiMaker publishes profiles in fdm_materials. |
/Cura/slicemetadata.json | The settings the file was sliced with. |
/Metadata/UFP_Global.json | Metadata about the package as a whole. |
/[Content_Types].xml | The media type for each extension. |
/_rels/.rels, /3D/_rels/model.gcode.rels | Relationships of the package and of the G-code. |
Content types
/[Content_Types].xml has the root element Types in the namespace
http://schemas.openxmlformats.org/package/2006/content-types, with one
Default element, with attributes Extension and
ContentType, per extension.
| Extension | Content type |
|---|---|
rels | application/vnd.openxmlformats-package.relationships+xml |
gcode | text/x-gcode |
json | application/json from Cura; libCharon on its own would add text/json |
png | image/png |
xml.fdm_material | application/x-ultimaker-material-profile |
Relationships
A relationship part is an XML file with the root Relationships in the namespace
http://schemas.openxmlformats.org/package/2006/relationships. Each
Relationship element has a Target (the full part name), a
Type and an Id (rel0, rel1 and so on). The
package’s relationships are in /_rels/.rels; those of the file
/3D/model.gcode are in /3D/_rels/model.gcode.rels.
<?xml version="1.0" encoding="UTF-8"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Target="/3D/model.gcode"
Type="http://schemas.ultimaker.org/package/2018/relationships/gcode" Id="rel0" />
</Relationships>
| From | To | Type |
|---|---|---|
| package | /3D/model.gcode | http://schemas.ultimaker.org/package/2018/relationships/gcode |
| G-code | thumbnail | http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail |
| G-code | each material profile | http://schemas.ultimaker.org/package/2018/relationships/material |
| package | each metadata JSON file | http://schemas.ultimaker.org/package/2018/relationships/opc_metadata |
Metadata files
libCharon keeps metadata as key paths such as metadata/objects and stores them in
JSON. Keys that belong to one part go into a file named after it with .json
added; all others go into /Metadata/UFP_Global.json. The slashes of a key become
nested objects, written with sorted keys and an indent of four spaces. Where a key has both a
value and keys below it, the value is stored under the empty name "".
A reader takes metadata only from files named by an opc_metadata
relationship.
Object list
Cura records the names of the printable objects:
{
"metadata": {
"objects": [
{ "name": "object name" }
]
}
}
UFP_Global.json as Cura fills it.Slice metadata
/Cura/slicemetadata.json is a JSON object written by Cura:
| Key | Contents |
|---|---|
material | length, weight and cost of the material, as Cura’s print information gives them. |
global | changes: the settings changed by the user or the quality profile. all_settings: the values of all machine-wide settings, taken without those changes in view. |
quality | The active quality profile, with the fields below. |
extruder_0, extruder_1 … | changes and all_settings for each extruder. |
The setting names are Cura’s own setting keys, and formulas are evaluated before they are written.
The quality object
The members are those of Cura’s ActiveQuality record, filled in by its machine manager.
| Key | Value |
|---|---|
intent_category | Name of the base intent, such as visual or engineering; default when no special intent is chosen |
intent_name | The intent name formatted for display, which may be translated |
profile | Name of the base quality profile, such as Fine |
custom_profile | Name of the user’s own profile built on it, or null when none is active |
layer_height | Layer height of the quality in millimetres, rounded to two decimals, or null when the active quality is not supported |
is_experimental | true for a supported experimental quality |
If there is no active printer, Cura builds the record from its defaults: empty strings,
null for layer_height and false.
The G-code header
When no metadata file describes the G-code, libCharon reads the comment header at the start of
/3D/model.gcode instead. The comments Cura writes are listed under
G-code comments.
- Lines of the form
;KEY.SUBKEY:valueare read; the key is lower-cased and split at dots. - Reading stops at
;LAYER, at;END_OF_HEADERor after about 100 lines. FLAVORmust beGriffin,CheetahorUltiGCode.- For Griffin and Cheetah,
HEADER_VERSIONmust be0.1, and these must be present:TARGET_MACHINE.NAME;GENERATOR.NAME,.VERSIONand.BUILD_DATE;BUILD_PLATE.INITIAL_TEMPERATURE;PRINT.SIZE.MINand.MAXin X, Y and Z;TIMEorPRINT.TIME; and for eachEXTRUDER_TRAIN.n present,NOZZLE.DIAMETER,MATERIAL.VOLUME_USEDandINITIAL_TEMPERATURE.
Recognising a file
The file starts like any ZIP (PK), and holds /[Content_Types].xml
and /3D/model.gcode. A 3MF package, which also has a 3D folder, holds
a .model file there instead of G-code.
Divergence from spec and in software
- OPC part names are stored in a ZIP without the leading slash; libCharon stores them with it and opens them by that name, so a package repacked the usual OPC way is not read by its code.
- libCharon defines a relationship type ending in
ufp_metadatafor UFP, but the code that writes and reads metadata uses the type ending inopc_metadata. - In libCharon’s code, a package with no metadata file for the G-code fails to open if the G-code header does not pass the checks above, for instance with another flavour.
- Cura’s own UFP reader loads only
/3D/model.gcode, as G-code. - Moonraker (the server used with Klipper) and the OctoPrint plugin for UFP extract the G-code and the thumbnail. Moonraker then deletes the package.
- libCharon offers the names
/toolpathand/previewas aliases for the G-code and the thumbnail, and can return a PNG resized (…png/300x300). These are features of the library; no such parts are stored.
In the explorer
Dropping a .ufp package on the explorer shows the ZIP records, a summary of the
print job, the thumbnail and the tool path of the G-code.
- The moves of
G0toG3in/3D/model.gcodeare drawn in 3D, extrusion and travel apart, in parts of 2,000,000 segments, and from above as a flat picture. Absolute and relative positions and extrusion,G92,G28, inch units and arcs by centre or radius are followed. Each layer marked by a;LAYERcomment opens as a picture of its own. - Tables list every part with its content type, the relationships, libCharon’s metadata, the
object names, the G-code header comments, every command with its count, the sum of the
Evalues for each tool, Cura’s slice metadata with all settings, and every element of the material profiles. Parts open as files. - Checks: parts that are missing, content types not declared, relationship targets not in the
package, entry names without the leading slash, metadata files no
opc_metadatarelationship names, a G-code header libCharon would refuse, and parts that are not well-formed. - Limits: a part is read up to 256 MB, so the tool path of a longer G-code ends there; the header comments are read from the first megabyte of the G-code.
Not described
The layout is taken from the source code of libCharon and Cura; no written specification of the package was found.
Known, not yet covered
- Viewer:
G5curves are not drawn, and arcs in the XZ and YZ planes are drawn as straight lines. - Viewer: volumetric extrusion, firmware retraction, tool offsets and work coordinate systems are listed among the commands but not applied to the tool path.
- Viewer: the tool path is not coloured by tool, feature type or speed.
Unknown
- Reference: which parts, relationships and metadata the firmware of UltiMaker printers requires or reads.
- Reference: parts that older or other writers may add beyond those that current Cura writes.
Links
Software
- UltiMaker Cura – slicer that writes and reads UFP (Windows, macOS, Linux)
- Moonraker – Klipper API server that unpacks uploaded UFP files (Linux)
- OctoPrint-UltimakerFormatPackage – OctoPrint plugin that accepts UFP uploads
Developers
- libCharon – UltiMaker’s library for reading and writing UFP (Python)
Reference
- libCharon file types – UltimakerFormatPackage.py, OpenPackagingConvention.py and GCodeFile.py
- Cura UFPWriter – the code that chooses the parts of a Cura package
- Cura API Settings.py – builds the slice metadata
- Cura ActiveQuality.py – the members of the quality object