bambu3mf 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bambu3mf-0.1.0/LICENSE +21 -0
- bambu3mf-0.1.0/PKG-INFO +246 -0
- bambu3mf-0.1.0/README.md +214 -0
- bambu3mf-0.1.0/pyproject.toml +45 -0
- bambu3mf-0.1.0/setup.cfg +4 -0
- bambu3mf-0.1.0/src/bambu3mf/__init__.py +30 -0
- bambu3mf-0.1.0/src/bambu3mf/config_writer.py +137 -0
- bambu3mf-0.1.0/src/bambu3mf/plate.py +166 -0
- bambu3mf-0.1.0/src/bambu3mf/presets.py +143 -0
- bambu3mf-0.1.0/src/bambu3mf/project.py +245 -0
- bambu3mf-0.1.0/src/bambu3mf/stl_loader.py +244 -0
- bambu3mf-0.1.0/src/bambu3mf.egg-info/PKG-INFO +246 -0
- bambu3mf-0.1.0/src/bambu3mf.egg-info/SOURCES.txt +23 -0
- bambu3mf-0.1.0/src/bambu3mf.egg-info/dependency_links.txt +1 -0
- bambu3mf-0.1.0/src/bambu3mf.egg-info/requires.txt +4 -0
- bambu3mf-0.1.0/src/bambu3mf.egg-info/top_level.txt +1 -0
- bambu3mf-0.1.0/tests/test_add_stl.py +299 -0
- bambu3mf-0.1.0/tests/test_config_writer.py +215 -0
- bambu3mf-0.1.0/tests/test_e2e.py +371 -0
- bambu3mf-0.1.0/tests/test_on_bed.py +65 -0
- bambu3mf-0.1.0/tests/test_plate.py +19 -0
- bambu3mf-0.1.0/tests/test_presets.py +231 -0
- bambu3mf-0.1.0/tests/test_project.py +246 -0
- bambu3mf-0.1.0/tests/test_stl_loader.py +83 -0
- bambu3mf-0.1.0/tests/test_version.py +66 -0
bambu3mf-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gavin Stark
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
bambu3mf-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bambu3mf
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python library for creating Bambu Studio 3MF files
|
|
5
|
+
Author: Gavin Stark
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/gstark/bambu3mf
|
|
8
|
+
Project-URL: Source, https://github.com/gstark/bambu3mf
|
|
9
|
+
Project-URL: Issues, https://github.com/gstark/bambu3mf/issues
|
|
10
|
+
Keywords: 3mf,bambu-studio,bambu-lab,3d-printing,slicer
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Manufacturing
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: lib3mf
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# bambu3mf
|
|
34
|
+
|
|
35
|
+
Python library for creating BambuStudio-compatible 3MF project files. Supports multi-plate layouts, per-object extruder assignment, and printer/filament preset configuration.
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install bambu3mf
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Requires Python 3.10+ and [lib3mf](https://github.com/3MFConsortium/lib3mf).
|
|
44
|
+
|
|
45
|
+
lib3mf publishes wheels only for Linux x86_64, macOS, and Windows x86_64. On other platforms, such as Linux on ARM, `pip install` fails.
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from bambu3mf import BambuProject
|
|
51
|
+
|
|
52
|
+
project = BambuProject(
|
|
53
|
+
printer_settings_id="Bambu Lab P1P 0.4 nozzle",
|
|
54
|
+
filaments=[
|
|
55
|
+
{"settings_id": "Bambu PLA Basic @BBL P1P", "colour": "#FF0000"},
|
|
56
|
+
{"settings_id": "Bambu PLA Basic @BBL P1P", "colour": "#0000FF"},
|
|
57
|
+
],
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
plate = project.add_plate(name="My Plate")
|
|
61
|
+
plate.add_stl("body.stl", extruder=1)
|
|
62
|
+
plate.add_stl("accent.stl", position=(150, 100), extruder=2)
|
|
63
|
+
|
|
64
|
+
project.save("output.3mf")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Open `output.3mf` in BambuStudio and it will load with correct plate layout, filament colors, and printer preset -- ready to slice.
|
|
68
|
+
|
|
69
|
+
## Examples
|
|
70
|
+
|
|
71
|
+
### Single Object, Auto-Centered
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from bambu3mf import BambuProject
|
|
75
|
+
|
|
76
|
+
project = BambuProject()
|
|
77
|
+
plate = project.add_plate()
|
|
78
|
+
plate.add_stl("model.stl") # centered on bed automatically
|
|
79
|
+
project.save("simple.3mf")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Multi-Plate Project
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from bambu3mf import BambuProject
|
|
86
|
+
|
|
87
|
+
project = BambuProject(
|
|
88
|
+
printer_settings_id="Bambu Lab X1 Carbon 0.4 nozzle",
|
|
89
|
+
filaments=[{"settings_id": "Bambu PLA Basic @BBL X1C", "colour": "#FFFFFF"}],
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
p1 = project.add_plate(name="Base Parts")
|
|
93
|
+
p1.add_stl("base_left.stl", position=(10, 10))
|
|
94
|
+
p1.add_stl("base_right.stl", position=(140, 10))
|
|
95
|
+
|
|
96
|
+
p2 = project.add_plate(name="Top Parts")
|
|
97
|
+
p2.add_stl("top.stl")
|
|
98
|
+
|
|
99
|
+
project.save("multi_plate.3mf")
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Plates are arranged in a grid layout matching BambuStudio's internal algorithm. Objects are assigned to plates by spatial position.
|
|
103
|
+
|
|
104
|
+
### Multi-Color Print
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from bambu3mf import BambuProject
|
|
108
|
+
|
|
109
|
+
project = BambuProject(
|
|
110
|
+
printer_settings_id="Bambu Lab P1S 0.4 nozzle",
|
|
111
|
+
filaments=[
|
|
112
|
+
{"settings_id": "Bambu PLA Basic @BBL P1S", "colour": "#000000", "type": "PLA"},
|
|
113
|
+
{"settings_id": "Bambu PLA Basic @BBL P1S", "colour": "#FF5733", "type": "PLA"},
|
|
114
|
+
{"settings_id": "Bambu PLA Basic @BBL P1S", "colour": "#FFFFFF", "type": "PLA"},
|
|
115
|
+
],
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
plate = project.add_plate()
|
|
119
|
+
plate.add_stl("frame.stl", extruder=1) # black
|
|
120
|
+
plate.add_stl("logo.stl", position=(80, 80), extruder=2) # orange
|
|
121
|
+
plate.add_stl("text.stl", position=(80, 120), extruder=3) # white
|
|
122
|
+
|
|
123
|
+
project.save("multicolor.3mf")
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Custom Bed Size (A1 Mini)
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from bambu3mf import BambuProject
|
|
130
|
+
|
|
131
|
+
project = BambuProject(
|
|
132
|
+
bed_size=(180, 180),
|
|
133
|
+
printer_settings_id="Bambu Lab A1 mini 0.4 nozzle",
|
|
134
|
+
)
|
|
135
|
+
plate = project.add_plate()
|
|
136
|
+
plate.add_stl("small_part.stl")
|
|
137
|
+
project.save("a1_mini.3mf")
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Description Metadata
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from bambu3mf import BambuProject
|
|
144
|
+
|
|
145
|
+
project = BambuProject(
|
|
146
|
+
description="<p>Print-in-place gearbox with 0.2mm clearance.</p>",
|
|
147
|
+
)
|
|
148
|
+
plate = project.add_plate(name="Main")
|
|
149
|
+
plate.add_stl("gearbox.stl")
|
|
150
|
+
project.save("described.3mf")
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
`description` is written to `<metadata name="Description">...</metadata>` in `3D/3dmodel.model`. If the value contains HTML-like text, it is XML-escaped in the 3MF archive.
|
|
154
|
+
|
|
155
|
+
### Slicing with the BambuStudio CLI
|
|
156
|
+
|
|
157
|
+
The BambuStudio CLI needs complete settings in the file. It segfaults on a file that holds only preset names.
|
|
158
|
+
|
|
159
|
+
When `printer_settings_id` is set, `save` reads the system presets of the installed BambuStudio and writes the complete settings. `print_settings_id` and the filament presets default to the defaults of the printer.
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
project = BambuProject(
|
|
163
|
+
printer_settings_id="Bambu Lab P1P 0.4 nozzle",
|
|
164
|
+
print_settings_id="0.20mm Standard @BBL P1P",
|
|
165
|
+
filaments=[{"settings_id": "Bambu PLA Basic @BBL P1P", "colour": "#FF0000"}],
|
|
166
|
+
)
|
|
167
|
+
project.add_plate().add_stl("part.stl")
|
|
168
|
+
project.save("part.3mf")
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
BambuStudio --slice 0 --outputdir "$PWD/out" --export-3mf sliced.3mf part.3mf
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
- `save` finds the profile folder on macOS and Windows. On other systems, pass `profiles_dir` (the `resources/profiles` folder of BambuStudio).
|
|
176
|
+
- If no profile folder is found, `save` writes only the preset names. The GUI can open that file. The CLI cannot.
|
|
177
|
+
- If a preset name is not in the profile folder, `save` gives a warning and writes only the preset names.
|
|
178
|
+
- `bed_size` defaults to the `printable_area` of the printer preset. If you pass `bed_size`, it must match the printer.
|
|
179
|
+
|
|
180
|
+
## API Reference
|
|
181
|
+
|
|
182
|
+
### `BambuProject`
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
BambuProject(
|
|
186
|
+
*,
|
|
187
|
+
bed_size=None, # (width, height) in mm (default: from the printer preset, else 256 x 256)
|
|
188
|
+
printer_settings_id="", # BambuStudio printer preset name
|
|
189
|
+
filaments=None, # list of filament dicts (see below)
|
|
190
|
+
app_version=None, # override Application metadata
|
|
191
|
+
description=None, # optional 3MF Description metadata (HTML text is XML-escaped)
|
|
192
|
+
profiles_dir=None, # BambuStudio profile folder (default: the installed app)
|
|
193
|
+
)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
**Filament dicts** accept these keys:
|
|
197
|
+
|
|
198
|
+
| Key | Default | Description |
|
|
199
|
+
|---|---|---|
|
|
200
|
+
| `settings_id` | `""` | BambuStudio filament preset name |
|
|
201
|
+
| `colour` | `"#00AE42"` | Hex color shown in slicer UI |
|
|
202
|
+
| `type` | `"PLA"` | Material type |
|
|
203
|
+
| `diameter` | `"1.75"` | Filament diameter in mm |
|
|
204
|
+
|
|
205
|
+
**Methods:**
|
|
206
|
+
|
|
207
|
+
- `add_plate(*, name=None)` -- Create a new plate. Returns a `Plate`. Plates are 1-indexed.
|
|
208
|
+
- `save(path)` -- Write the 3MF file.
|
|
209
|
+
|
|
210
|
+
### `Plate`
|
|
211
|
+
|
|
212
|
+
Created via `project.add_plate()`. Do not instantiate directly.
|
|
213
|
+
|
|
214
|
+
**Methods:**
|
|
215
|
+
|
|
216
|
+
- `add_stl(path, *, position=None, extruder=1)` -- Load an STL onto this plate.
|
|
217
|
+
- `position`: `(x, y)` in mm for the object's min corner, relative to plate origin. `None` to auto-center.
|
|
218
|
+
- `extruder`: 1-indexed filament slot.
|
|
219
|
+
- Returns a dict with `resource_id`, `vertex_count`, `triangle_count`, `bounding_box`.
|
|
220
|
+
- Raises `FileNotFoundError` if the STL doesn't exist.
|
|
221
|
+
- Raises `ValueError` if the object exceeds bed bounds at the given position.
|
|
222
|
+
|
|
223
|
+
## How It Works
|
|
224
|
+
|
|
225
|
+
The library generates a valid 3MF ZIP archive containing:
|
|
226
|
+
|
|
227
|
+
| File | Format | Purpose |
|
|
228
|
+
|---|---|---|
|
|
229
|
+
| `3D/3dmodel.model` | XML | Mesh geometry with BambuStudio namespace |
|
|
230
|
+
| `Metadata/project_settings.config` | JSON | Printer, filament, and bed configuration |
|
|
231
|
+
| `Metadata/model_settings.config` | XML | Per-object metadata and plate layout |
|
|
232
|
+
|
|
233
|
+
Mesh geometry is handled by [lib3mf](https://github.com/3MFConsortium/lib3mf). BambuStudio-specific metadata (namespace, version, config files) is injected post-write since lib3mf has no API for custom namespaces.
|
|
234
|
+
|
|
235
|
+
**Key compatibility detail:** BambuStudio assigns objects to plates by spatial bounding-box intersection, not by the plate-to-object mapping in config. The library handles this automatically by positioning objects in the correct grid cell.
|
|
236
|
+
|
|
237
|
+
## Development
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
pip install -e ".[dev]"
|
|
241
|
+
pytest
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## License
|
|
245
|
+
|
|
246
|
+
See [LICENSE](LICENSE) for details.
|
bambu3mf-0.1.0/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# bambu3mf
|
|
2
|
+
|
|
3
|
+
Python library for creating BambuStudio-compatible 3MF project files. Supports multi-plate layouts, per-object extruder assignment, and printer/filament preset configuration.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install bambu3mf
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires Python 3.10+ and [lib3mf](https://github.com/3MFConsortium/lib3mf).
|
|
12
|
+
|
|
13
|
+
lib3mf publishes wheels only for Linux x86_64, macOS, and Windows x86_64. On other platforms, such as Linux on ARM, `pip install` fails.
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from bambu3mf import BambuProject
|
|
19
|
+
|
|
20
|
+
project = BambuProject(
|
|
21
|
+
printer_settings_id="Bambu Lab P1P 0.4 nozzle",
|
|
22
|
+
filaments=[
|
|
23
|
+
{"settings_id": "Bambu PLA Basic @BBL P1P", "colour": "#FF0000"},
|
|
24
|
+
{"settings_id": "Bambu PLA Basic @BBL P1P", "colour": "#0000FF"},
|
|
25
|
+
],
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
plate = project.add_plate(name="My Plate")
|
|
29
|
+
plate.add_stl("body.stl", extruder=1)
|
|
30
|
+
plate.add_stl("accent.stl", position=(150, 100), extruder=2)
|
|
31
|
+
|
|
32
|
+
project.save("output.3mf")
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Open `output.3mf` in BambuStudio and it will load with correct plate layout, filament colors, and printer preset -- ready to slice.
|
|
36
|
+
|
|
37
|
+
## Examples
|
|
38
|
+
|
|
39
|
+
### Single Object, Auto-Centered
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from bambu3mf import BambuProject
|
|
43
|
+
|
|
44
|
+
project = BambuProject()
|
|
45
|
+
plate = project.add_plate()
|
|
46
|
+
plate.add_stl("model.stl") # centered on bed automatically
|
|
47
|
+
project.save("simple.3mf")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Multi-Plate Project
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from bambu3mf import BambuProject
|
|
54
|
+
|
|
55
|
+
project = BambuProject(
|
|
56
|
+
printer_settings_id="Bambu Lab X1 Carbon 0.4 nozzle",
|
|
57
|
+
filaments=[{"settings_id": "Bambu PLA Basic @BBL X1C", "colour": "#FFFFFF"}],
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
p1 = project.add_plate(name="Base Parts")
|
|
61
|
+
p1.add_stl("base_left.stl", position=(10, 10))
|
|
62
|
+
p1.add_stl("base_right.stl", position=(140, 10))
|
|
63
|
+
|
|
64
|
+
p2 = project.add_plate(name="Top Parts")
|
|
65
|
+
p2.add_stl("top.stl")
|
|
66
|
+
|
|
67
|
+
project.save("multi_plate.3mf")
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Plates are arranged in a grid layout matching BambuStudio's internal algorithm. Objects are assigned to plates by spatial position.
|
|
71
|
+
|
|
72
|
+
### Multi-Color Print
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from bambu3mf import BambuProject
|
|
76
|
+
|
|
77
|
+
project = BambuProject(
|
|
78
|
+
printer_settings_id="Bambu Lab P1S 0.4 nozzle",
|
|
79
|
+
filaments=[
|
|
80
|
+
{"settings_id": "Bambu PLA Basic @BBL P1S", "colour": "#000000", "type": "PLA"},
|
|
81
|
+
{"settings_id": "Bambu PLA Basic @BBL P1S", "colour": "#FF5733", "type": "PLA"},
|
|
82
|
+
{"settings_id": "Bambu PLA Basic @BBL P1S", "colour": "#FFFFFF", "type": "PLA"},
|
|
83
|
+
],
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
plate = project.add_plate()
|
|
87
|
+
plate.add_stl("frame.stl", extruder=1) # black
|
|
88
|
+
plate.add_stl("logo.stl", position=(80, 80), extruder=2) # orange
|
|
89
|
+
plate.add_stl("text.stl", position=(80, 120), extruder=3) # white
|
|
90
|
+
|
|
91
|
+
project.save("multicolor.3mf")
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Custom Bed Size (A1 Mini)
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from bambu3mf import BambuProject
|
|
98
|
+
|
|
99
|
+
project = BambuProject(
|
|
100
|
+
bed_size=(180, 180),
|
|
101
|
+
printer_settings_id="Bambu Lab A1 mini 0.4 nozzle",
|
|
102
|
+
)
|
|
103
|
+
plate = project.add_plate()
|
|
104
|
+
plate.add_stl("small_part.stl")
|
|
105
|
+
project.save("a1_mini.3mf")
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Description Metadata
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from bambu3mf import BambuProject
|
|
112
|
+
|
|
113
|
+
project = BambuProject(
|
|
114
|
+
description="<p>Print-in-place gearbox with 0.2mm clearance.</p>",
|
|
115
|
+
)
|
|
116
|
+
plate = project.add_plate(name="Main")
|
|
117
|
+
plate.add_stl("gearbox.stl")
|
|
118
|
+
project.save("described.3mf")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`description` is written to `<metadata name="Description">...</metadata>` in `3D/3dmodel.model`. If the value contains HTML-like text, it is XML-escaped in the 3MF archive.
|
|
122
|
+
|
|
123
|
+
### Slicing with the BambuStudio CLI
|
|
124
|
+
|
|
125
|
+
The BambuStudio CLI needs complete settings in the file. It segfaults on a file that holds only preset names.
|
|
126
|
+
|
|
127
|
+
When `printer_settings_id` is set, `save` reads the system presets of the installed BambuStudio and writes the complete settings. `print_settings_id` and the filament presets default to the defaults of the printer.
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
project = BambuProject(
|
|
131
|
+
printer_settings_id="Bambu Lab P1P 0.4 nozzle",
|
|
132
|
+
print_settings_id="0.20mm Standard @BBL P1P",
|
|
133
|
+
filaments=[{"settings_id": "Bambu PLA Basic @BBL P1P", "colour": "#FF0000"}],
|
|
134
|
+
)
|
|
135
|
+
project.add_plate().add_stl("part.stl")
|
|
136
|
+
project.save("part.3mf")
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
BambuStudio --slice 0 --outputdir "$PWD/out" --export-3mf sliced.3mf part.3mf
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
- `save` finds the profile folder on macOS and Windows. On other systems, pass `profiles_dir` (the `resources/profiles` folder of BambuStudio).
|
|
144
|
+
- If no profile folder is found, `save` writes only the preset names. The GUI can open that file. The CLI cannot.
|
|
145
|
+
- If a preset name is not in the profile folder, `save` gives a warning and writes only the preset names.
|
|
146
|
+
- `bed_size` defaults to the `printable_area` of the printer preset. If you pass `bed_size`, it must match the printer.
|
|
147
|
+
|
|
148
|
+
## API Reference
|
|
149
|
+
|
|
150
|
+
### `BambuProject`
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
BambuProject(
|
|
154
|
+
*,
|
|
155
|
+
bed_size=None, # (width, height) in mm (default: from the printer preset, else 256 x 256)
|
|
156
|
+
printer_settings_id="", # BambuStudio printer preset name
|
|
157
|
+
filaments=None, # list of filament dicts (see below)
|
|
158
|
+
app_version=None, # override Application metadata
|
|
159
|
+
description=None, # optional 3MF Description metadata (HTML text is XML-escaped)
|
|
160
|
+
profiles_dir=None, # BambuStudio profile folder (default: the installed app)
|
|
161
|
+
)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Filament dicts** accept these keys:
|
|
165
|
+
|
|
166
|
+
| Key | Default | Description |
|
|
167
|
+
|---|---|---|
|
|
168
|
+
| `settings_id` | `""` | BambuStudio filament preset name |
|
|
169
|
+
| `colour` | `"#00AE42"` | Hex color shown in slicer UI |
|
|
170
|
+
| `type` | `"PLA"` | Material type |
|
|
171
|
+
| `diameter` | `"1.75"` | Filament diameter in mm |
|
|
172
|
+
|
|
173
|
+
**Methods:**
|
|
174
|
+
|
|
175
|
+
- `add_plate(*, name=None)` -- Create a new plate. Returns a `Plate`. Plates are 1-indexed.
|
|
176
|
+
- `save(path)` -- Write the 3MF file.
|
|
177
|
+
|
|
178
|
+
### `Plate`
|
|
179
|
+
|
|
180
|
+
Created via `project.add_plate()`. Do not instantiate directly.
|
|
181
|
+
|
|
182
|
+
**Methods:**
|
|
183
|
+
|
|
184
|
+
- `add_stl(path, *, position=None, extruder=1)` -- Load an STL onto this plate.
|
|
185
|
+
- `position`: `(x, y)` in mm for the object's min corner, relative to plate origin. `None` to auto-center.
|
|
186
|
+
- `extruder`: 1-indexed filament slot.
|
|
187
|
+
- Returns a dict with `resource_id`, `vertex_count`, `triangle_count`, `bounding_box`.
|
|
188
|
+
- Raises `FileNotFoundError` if the STL doesn't exist.
|
|
189
|
+
- Raises `ValueError` if the object exceeds bed bounds at the given position.
|
|
190
|
+
|
|
191
|
+
## How It Works
|
|
192
|
+
|
|
193
|
+
The library generates a valid 3MF ZIP archive containing:
|
|
194
|
+
|
|
195
|
+
| File | Format | Purpose |
|
|
196
|
+
|---|---|---|
|
|
197
|
+
| `3D/3dmodel.model` | XML | Mesh geometry with BambuStudio namespace |
|
|
198
|
+
| `Metadata/project_settings.config` | JSON | Printer, filament, and bed configuration |
|
|
199
|
+
| `Metadata/model_settings.config` | XML | Per-object metadata and plate layout |
|
|
200
|
+
|
|
201
|
+
Mesh geometry is handled by [lib3mf](https://github.com/3MFConsortium/lib3mf). BambuStudio-specific metadata (namespace, version, config files) is injected post-write since lib3mf has no API for custom namespaces.
|
|
202
|
+
|
|
203
|
+
**Key compatibility detail:** BambuStudio assigns objects to plates by spatial bounding-box intersection, not by the plate-to-object mapping in config. The library handles this automatically by positioning objects in the correct grid cell.
|
|
204
|
+
|
|
205
|
+
## Development
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
pip install -e ".[dev]"
|
|
209
|
+
pytest
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
See [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "bambu3mf"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python library for creating Bambu Studio 3MF files"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Gavin Stark" }]
|
|
14
|
+
keywords = ["3mf", "bambu-studio", "bambu-lab", "3d-printing", "slicer"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Intended Audience :: Manufacturing",
|
|
19
|
+
"Operating System :: MacOS",
|
|
20
|
+
"Operating System :: Microsoft :: Windows",
|
|
21
|
+
"Operating System :: POSIX :: Linux",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Programming Language :: Python :: 3.14",
|
|
29
|
+
"Topic :: Multimedia :: Graphics :: 3D Modeling",
|
|
30
|
+
]
|
|
31
|
+
dependencies = ["lib3mf"]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/gstark/bambu3mf"
|
|
35
|
+
Source = "https://github.com/gstark/bambu3mf"
|
|
36
|
+
Issues = "https://github.com/gstark/bambu3mf/issues"
|
|
37
|
+
|
|
38
|
+
[project.optional-dependencies]
|
|
39
|
+
dev = ["pytest>=7.0"]
|
|
40
|
+
|
|
41
|
+
[tool.pytest.ini_options]
|
|
42
|
+
testpaths = ["tests"]
|
|
43
|
+
|
|
44
|
+
[tool.setuptools.packages.find]
|
|
45
|
+
where = ["src"]
|
bambu3mf-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Python library for creating BambuStudio-compatible 3MF project files.
|
|
2
|
+
|
|
3
|
+
Generates 3MF archives that open cleanly in BambuStudio with full support
|
|
4
|
+
for multi-plate layouts, per-object filament/extruder assignment, and
|
|
5
|
+
printer/filament preset configuration.
|
|
6
|
+
|
|
7
|
+
Quick start::
|
|
8
|
+
|
|
9
|
+
from bambu3mf import BambuProject
|
|
10
|
+
|
|
11
|
+
project = BambuProject(
|
|
12
|
+
printer_settings_id="Bambu Lab P1P 0.4 nozzle",
|
|
13
|
+
filaments=[
|
|
14
|
+
{"settings_id": "Bambu PLA Basic @BBL P1P", "colour": "#FF0000"},
|
|
15
|
+
{"settings_id": "Bambu PLA Basic @BBL P1P", "colour": "#0000FF"},
|
|
16
|
+
],
|
|
17
|
+
)
|
|
18
|
+
plate = project.add_plate(name="My Plate")
|
|
19
|
+
plate.add_stl("model_a.stl", extruder=1)
|
|
20
|
+
plate.add_stl("model_b.stl", position=(150, 100), extruder=2)
|
|
21
|
+
project.save("output.3mf")
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from importlib.metadata import version
|
|
25
|
+
|
|
26
|
+
from bambu3mf.plate import Plate
|
|
27
|
+
from bambu3mf.project import BambuProject
|
|
28
|
+
|
|
29
|
+
__version__ = version("bambu3mf")
|
|
30
|
+
__all__ = ["BambuProject", "Plate"]
|