Export active Spoolman spools' data to filament configuration files for 3D printer slicers
Project description
Spoolman to slicer config generator
Intro
A python program to export active Spoolman spools' data to filament configurations files for:
It is easy be extended it 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.
The workflow
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
usage: spoolman2slicer.py [-h] [--version] -d DIR
[-s {orcaslicer,prusaslicer,slic3r,superslicer}]
[-u URL] [-U] [-v] [-V VALUE1,VALUE2..] [-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 slicer's 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'reupdated 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
Usage Docker-Compose
Update the Environment Variables and mount points in docker-compose and run:
docker-compose up -d
for advanced cli arguments use:
entrypoint: [ "sh", "-c", "python3 ./spoolman2slicer.py #AddYourArgumentsHere" ]
Installation
From PyPI (Recommended)
The easiest way to install spoolman2slicer is from PyPI:
pip install spoolman2slicer
After installation, you can run it directly:
spoolman2slicer -s orcaslicer -d ~/.config/OrcaSlicer/user/default/filament/
From Source
If you want to run from source, clone the repository and run:
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
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 stored with the filaments' material's name in
<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.
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
--variantsargument, 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.
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',
'variants': 'printer1',
'spoolman_url': 'http://mainsailos.local:7912'
}
}
Creating templates from existing config
The create_template_files.py program can create basic template files
by copying existing filament config files.
Run it like this:
./create_template_files.py -s orcaslicer -v
If the program doesn't find the slicers' config dir, use the -d option:
./create_template_files.py -s orcaslicer -v -d "path/to/slicers/filament/config/dir"
If that's needed, please create/update a github issue with your operating system, the slicer and the path where you found the filament config files.
If needed, the program will create the templates' config dir and
copy the filename.template file there.
For every filament config file in the slicer, it will create a template file for its material, unless the material already has a template file.
The generated files might work for you, but you should check them before using them. The start gcode probably needs updates as well as the first layer temperatures.
Writing the templates
The default templates as well as the generated template files are based on my settings. 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 has added the Voron filaments in Orca Slicer as they inherit from them (but that's not the case for the generated files).
When making your own, it is best to start with the generated files and update the files' fields to fit your preferences.
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 use the default one, unless you
want different styles for your filenames.
You should also have a default.<suffix>.template file (or two with
OrcaSlicer, one for the .info file as well). It will be used if there is no
material specific template file. I've just copied the PLA templates.
The templates are quite advanced. Follow the link above to jinja2 to read its documentation.
The Jinja Playground program can help when editing the templates, by providing instant feedback.
Generating for multiple printers, the variants argument
When using the --variants argument, it should have two or more more
values, separated by commas. Ie --variants printer_small,printer_big.
spoolman2slicer then generates one set of files per value.
Each time sm2s.variant will have one of the given values.
The templates can check the variable and output different fields or values depending on it. Ie:
start_filament_gcode = "; Filament gcode\nSET_PRESSURE_ADVANCE={% if sm2s.variant == "printer_big %}{{extra.pressure_advance_big|default(0)|float}}{% else %}"{{extra.pressure_advance_small|default(0)|float}}{% endif %}\n"
The default filename.template file uses the variant variable to put
the variant first in the filename, if given, but the other template files don't use it.
Run
Ubuntu & OrcaSlicer
./spoolman2slicer.py -s orcaslicer -U -d ~/.config/OrcaSlicer/user/default/filament/
Ubuntu & PrusaSlicer
./spoolman2slicer.py -s prusaslicer -U -d ~/.var/app/com.prusa3d.PrusaSlicer/config/PrusaSlicer/filament/
Ubuntu & SuperSlicer
./spoolman2slicer.py -U -d ~/.config/SuperSlicer/filament/
MacOs & OrcaSlicer
./spoolman2slicer.py -s orcaslicer -U -d ~/Library/Application\ Support/OrcaSlicer/user/default/filament
See the other options above.
Development
Please format the code with make fmt, run the tests with make test
and lint it with make lint before making a PR.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spoolman2slicer-0.0.3.tar.gz.
File metadata
- Download URL: spoolman2slicer-0.0.3.tar.gz
- Upload date:
- Size: 35.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fb9f10af160dd5357d22271ee9fc9964bfb88c162802014d918817c360ea7f0
|
|
| MD5 |
0afc0e322af3245e4db3483a08143df5
|
|
| BLAKE2b-256 |
c37ecae1790309d28654053db8b8c46a913e5f00d01e00455228764da85be762
|
Provenance
The following attestation bundles were made for spoolman2slicer-0.0.3.tar.gz:
Publisher:
publish-pypi.yml on bofh69/spoolman2slicer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spoolman2slicer-0.0.3.tar.gz -
Subject digest:
4fb9f10af160dd5357d22271ee9fc9964bfb88c162802014d918817c360ea7f0 - Sigstore transparency entry: 687212329
- Sigstore integration time:
-
Permalink:
bofh69/spoolman2slicer@07832da7c949ee2bac0097c5c828df4ba8fb01ec -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/bofh69
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@07832da7c949ee2bac0097c5c828df4ba8fb01ec -
Trigger Event:
release
-
Statement type:
File details
Details for the file spoolman2slicer-0.0.3-py3-none-any.whl.
File metadata
- Download URL: spoolman2slicer-0.0.3-py3-none-any.whl
- Upload date:
- Size: 38.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20a8bd13c78cb610c800803c06689abe41d2c7415922f5e3f6c07333e9761ce2
|
|
| MD5 |
5ed2cae092cc75efbfae174bd5af47b6
|
|
| BLAKE2b-256 |
48942a2e40b36ef995cba95818d45499fad205818e57854ff8c5b0bd76dafd3e
|
Provenance
The following attestation bundles were made for spoolman2slicer-0.0.3-py3-none-any.whl:
Publisher:
publish-pypi.yml on bofh69/spoolman2slicer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spoolman2slicer-0.0.3-py3-none-any.whl -
Subject digest:
20a8bd13c78cb610c800803c06689abe41d2c7415922f5e3f6c07333e9761ce2 - Sigstore transparency entry: 687212335
- Sigstore integration time:
-
Permalink:
bofh69/spoolman2slicer@07832da7c949ee2bac0097c5c828df4ba8fb01ec -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/bofh69
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@07832da7c949ee2bac0097c5c828df4ba8fb01ec -
Trigger Event:
release
-
Statement type: