A python program to create filament configurations in OrcaSlicer and SuperSlicer from the active spools in Spoolman's database.'
It could easily be extended to support more slicers.
The filament configuration files are based on templates. My templates are included in the repo, but you should make your own based on your settings. See below for how to do that.
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.
The next time you start the slicer you will see the available filaments.
My templates contain a "filament_start_gcode" command, ASSERT_ACTIVE_FILAMENT ID={{id}}
,
which comes from
this file in
my other repo, nfc2klipper.
It will run whenever the print starts to use that filament.
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.
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.
usage: spoolman2slicer.py [-h] [--version] -d DIR
[-s {orcaslicer,prusaslicer,slic3r,superslicer}]
[-u URL] [-U] [-D]
Fetches filaments 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 filament config dir
-s {orcaslicer,prusaslicer,slic3r,superslicer}, --slicer {orcaslicer,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
-D, --delete-all delete all filament configs before adding existing
ones
Run:
virtualenv venv
. venv/bin/activate
pip install -r requirements.txt
spoolman2slicer uses Jinja2 templates for the configuration files it creates and it also uses such a template for the configuration files' names.
The templates are stored with the filaments' material's name in
$HOME/.config/spoolman2slicer/templates-<slicer>/<material>.<suffix>.template
.
Where 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).
The variables available to use in the templates comes from the return data from Spoolman's filament request, 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.
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.
With my Spoolman install the 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',
'extra': {
'pressure_advance': '0.045'
},
'sm2s': {
'name': 'spoolman2slicer.py',
'version': '0.0.1',
'now': 'Sun Jan 26 10:57:51 2025',
'now_int': 1737885471,
'slicer_suffix': 'ini'
}
}
The default templates are based on mine. They assume there is an extra Spoolman filament field defined called "pressure_advance" and sets the pressure advance settings based on it. The Orca Slicer files also assumes one had added the Voron filaments in Orca Slicer as they inherit from them.
When making your own, it is better to copy your existing filament settings files (one per material) and update the files' fields to use the available variables.
To generate your own templates, copy your existing filament settings
from the slicer's config dir (on linux: ~/.config/SuperSlicer/filament/
or
~/.config/OrcaSlicer/user/default/filament/
) to the template dir and
name it like described above.
In the templates, variables are surrounded by {
and }
.
For variables with values that contain more variables, you write all
the variable names with a dot between. Ie the vendor's name (Gilford
above) is written as: {vendor.name}
. Be careful to use the same style as
the original file. If the file wrote "Gilford"
, remember to keep the
"
characters around the variable.
There is one special template file, the filename.template
. It is used to create
the name of the generated files. Just copy the default one.
The templates are quite advanced. Follow the link above to jinja2 to read its documentation.
./spoolman2slicer.py -U -d ~/.config/SuperSlicer/filament/
./spoolman2slicer.py -s orcaslicer -U -d ~/.config/OrcaSlicer/user/default/filament/
./spoolman2slicer.py -s orcaslicer -U -d ~/Library/Application\ Support/OrcaSlicer/user/default/filament
See the other options above.
Please format the code with make fmt
and lint it with make lint
before making a PR.