SkillAgentSearch skills...

Spoolman2slicer

Spoolman to slicer filament transfer

Install / Use

/learn @bofh69/Spoolman2slicer
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<!-- SPDX-FileCopyrightText: 2024-2025 Sebastian Andersson <sebastian@bittr.nu> SPDX-License-Identifier: GPL-3.0-or-later -->

REUSE status GitHub Workflow Status

Spoolman to slicer config generator

Intro

spoolman2slicer is a program to export Spoolman's data to filament configuration files for:

The filament configuration files are created from templates.

Table of Contents

<!--TOC--> <!--TOC-->

The workflow

Files from filaments

You add your spools' manufacturers, filaments and the spools to Spoolman.

For each filament that has at least one active spool, spoolman2slicer creates a filament configuration based on the filament.

The next time you start the slicer you will see the available filaments.

The templates contain a "filament_start_gcode" field, ASSERT_ACTIVE_FILAMENT ID={{id}}, which comes from this file in my other repo, nfc2klipper.

That macro checks that the active_filament variable is the same as the choosen filament.

The active_filament variable is set by first calling SET_ACTIVE_FILAMENT ID= and the id. That is called automatically by nfc2klipper.

If not using nfc2klipper, there is a Moonraker agent spool2klipper that can be used to update the active_filament variable whenever the spool is changed in moonraker (via frontends, code macros) etc.

Files from spools

A different workflow is possible and supported by spoolman2slicer.

Instead of letting the slicer's generated gcode to verify that the right filament has been loaded (no matter which spool it comes from), one can make it set the spool in Klipper during the start of the print.

The --create-per-spool command line option causes spoolman2slicer to generate one filament configuration file per spool, one for the most used spool or one for the latest used spool. The default templates will then use "SET_ACTIVE_SPOOL ID={{spool.id}}" in the "filament_start_gcode" field.

When creating one file for every spool, it uses the filename_for_spool.template file to create the filenames, otherwise the filename.template file is used to create the filenames.

The included filename_for_spool.template simply appends the spool's id to the filename. That's often not very helpful for selecting the right spool in the slicer. Depending on the data you've added to the spool's different fields could be better. The {{spool}} field contains all the fields from the Spoolman's spool object. {{spool.lot_nr}} or {{spool.location}} might be better options for you. You can also add an extra field in Spoolman's config for the spools and use that field here, ie {{spool.extra.my_label}}.

The default template files also use - {{spool.id}} at the end of the "name" field in the templates that use a name. If you update the filename template, update the name field too.

Usage

usage: spoolman2slicer [-h] [--version] -d DIR
                          [-s {orcaslicer,crealityprint,prusaslicer,slic3r,superslicer}]
                          [-u URL] [-U] [-v] [-V VALUE1,VALUE2..] [-D]
                          [--create-per-spool {all,least-left,most-recent}]

Fetches data from Spoolman and creates slicer filament config files.

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -d DIR, --dir DIR     the slicer's filament config dir
  -s {orcaslicer,crealityprint,prusaslicer,slic3r,superslicer}, --slicer {orcaslicer,crealityprint,prusaslicer,slic3r,superslicer}
                        the slicer
  -u URL, --url URL     URL for the Spoolman installation
  -U, --updates         keep running and update filament configs if they're
                        updated in Spoolman
  -v, --verbose         verbose output
  -V VALUE1,VALUE2.., --variants VALUE1,VALUE2..
                        write one template per value, separated by comma
  -D, --delete-all      delete all filament configs before adding existing
                        ones
  --create-per-spool {all,least-left,most-recent}
                        create one output file per spool instead of per filament.
                        'all': one file per spool.
                        'least-left': one file per filament for the spool having the least filament left.
                        'most-recent': one file per filament for the spool being most recently used.

Installation

From PyPI (Recommended)

The easiest way to install spoolman2slicer is from PyPI:

python3 -m venv path-to-venv
source path-to-venv/bin/activate
pip install spoolman2slicer

The default templates files are then under venv/lib/python3.12/site-packages/spoolman2slicer/data/.

spoolman2slicer is then runable from the virtual environment:

source path-to-venv/bin/active
spoolman2slicer

or

path-to-venv/bin/spoolman2slicer

Using Docker/Docker-Compose

spoolman2slicer can be run from docker.

Included is a Dockerfile and docker-compose config. Before using it, update the environment variables and mount points in docker-compose and run:

  docker-compose up -d

for other arguments to the command, use:

  entrypoint: [ "sh", "-c", "python3 ./spoolman2slicer/spoolman2slicer.py #AddYourArgumentsHere" ]

From Source

If you want to run from source, clone the repository and run:

python3 -m venv venv
source venv/bin/activate
pip install -e .
spoolman2slicer

Configuring the filament config templates

Intro

spoolman2slicer uses Jinja2 templates for the configuration files it creates and it also uses such a template for the configuration files' names.

Where the files are read from

The templates are read with the filaments' material's name from <configdir>/spoolman2slicer/templates-<slicer>/<material>.<suffix>.template.

<configdir> depends on the operating system:

| OS | Path | | :------ | :---------------------------------- | | Linux | $HOME/.config | | MacOS | $HOME/Library/Application Support | | Windows | %APPDATA% |

slicer is the used slicer (superslicer or orcaslicer). <material> is the material used in the filament in Spoolman, ie PLA, ABS etc. <suffix> is ini for Super Slicer, info and json for Orca Slicer (it uses two files per filament).

If the material isn't found, "default" is used as the material name.

Available variables in the templates

The variables available to use in the templates comes from the return data from Spoolman's filament request, described here.

When using the --create-per-spool argument, the spool field contains Spoolman's spool's fields, as described here.

spoolman2slicer also adds its own fields under the sm2s field:

  • name - the name of the tool's program file.
  • version - the version of the tool.
  • now - the time when the file is created.
  • now_int - the time when the file is created as the number of seconds since UNIX' epoch.
  • slicer_suffix - the filename's suffix.
  • variant - one of the comma separated values given to the --variants argument, or an empty string.
  • spoolman_url - the URL to spoolman.

The available variables, and their values, can be printed by spoolman2slicer when the filament is about to be written. Use the -v argument as argument to spoolman2slicer when it is started.

Output can look like this (after pretty printing it):

{
  'id': 17,
  'registered': '2024-10-08T12:23:04Z',
  'name': 'Gilford PLA+ Black',
  'vendor': {
    'id': 8,
    'registered': '2024-10-08T12:20:15Z',
    'name': 'Gilford',
    'extra': {}
  },
  'material': 'PLA',
  'price': 250.0,
  'density': 1.24,
  'diameter': 1.75,
  'weight': 1000.0,
  'spool_weight': 116.0,
  'article_number': '102001A',
  'settings_extruder_temp': 190,
  'settings_bed_temp': 60,
  'color_hex': '000000
View on GitHub
GitHub Stars96
CategoryDevelopment
Updated13h ago
Forks13

Languages

Python

Security Score

100/100

Audited on Mar 26, 2026

No findings