2.9 KiB
3MF CLI — Standard Operating Procedure
Overview
The 3MF CLI (cli-anything-3mf) is an agent-native command-line interface for
inspecting, modifying, and repairing 3MF mesh files used in 3D printing.
Unlike traditional 3D-printing CLI tools (PrusaSlicer CLI, BambuStudio CLI, admesh) that treat meshes as opaque triangle soups, this tool provides feature-aware geometry editing — it can detect cylindrical holes, measure their diameters, and resize them via CLI commands.
3MF Format
A 3MF file is a ZIP archive containing:
[Content_Types].xml— MIME type declarations_rels/.rels— relationship definitions3D/3dmodel.model— XML mesh data (core spec namespace:http://schemas.microsoft.com/3dmanufacturing/core/2015/02)Metadata/— slicer settings, thumbnails, plate configurations (BambuStudio, PrusaSlicer)
Architecture
threemf_cli.py Click CLI + REPL entry point
|
+-- core/parser.py 3MF ZIP/XML parsing, lossless repack
+-- core/inspector.py Cross-section hole detection
+-- core/modifier.py Radial vertex scaling for hole resize
+-- core/repair.py Degenerate face removal, vertex merge
|
+-- utils/threemf_backend.py trimesh/numpy geometry utilities
+-- utils/repl_skin.py Unified REPL styling
Core Algorithm
Hole Detection (inspector.py)
- Take N cross-sections perpendicular to the hole axis
- At each section, identify circular entities via trimesh path analysis
- Fit circles using least-squares (Kasa method)
- Group circles across sections by center proximity
- Calculate confidence from detection consistency
Hole Resize (modifier.py)
- Re-detect holes to get current geometry
- Find wall vertices at known radii from hole axis
- Scale vertices radially:
new_pos = center + direction * (new_r / old_r) - Fix degenerate faces caused by coincident vertices
Mesh Repair (repair.py)
- Merge duplicate vertices (coordinate rounding + dedup)
- Remove degenerate triangles (collapsed faces)
- Remove unreferenced vertices
- Fix face winding via trimesh
Slicer Compatibility
The tool preserves all non-mesh content during repack:
- BambuStudio: project_settings.config, model_settings.config, plate thumbnails
- PrusaSlicer: slic3r_pe configs, layer height profiles
Mesh triangle attributes are also preserved when the corresponding triangle is
kept. This includes material/property attributes such as pid, p1, p2, and
p3, plus unknown vendor attributes on <triangle> elements.
Component-only objects and build/component transform attributes are preserved
as untouched XML when writing files loaded from an existing 3MF archive. The
current geometry operations do not resolve component transforms into mesh
coordinates and cannot edit component-instance transforms directly.
Output files can be reopened in the original slicer without configuration loss.