-
Notifications
You must be signed in to change notification settings - Fork 3
G‐code Analysis and Processing
3D Model Muncher can analyze G-code files to extract print metadata such as estimated print time, filament usage, and material information. This data is stored alongside your model's metadata and displayed in the Model Details panel.
- Supported Formats
- Extracted Metadata
- How to Upload G-code
- Storage Modes
- Supported Slicers
- Data Storage
- API Reference
- Technical Details
3D Model Muncher supports two G-code file formats:
| Format | Extension | Description |
|---|---|---|
| Plain G-code | .gcode |
Standard G-code text files |
| BambuLab Archive | .gcode.3mf |
ZIP archives containing G-code in Metadata/plate_N.gcode
|
BambuLab slicers (BambuStudio, Orca Slicer) produce .gcode.3mf files which are ZIP archives containing:
- Project metadata
- Thumbnails and previews
- G-code files in
Metadata/plate_1.gcode,Metadata/plate_2.gcode, etc.
When uploading a .gcode.3mf file, the application extracts and parses the G-code while preserving the original archive intact.
The G-code parser extracts the following information:
| Field | Description | Example |
|---|---|---|
| Print Time | Estimated total print duration | 3h 14m |
| Filament Type | Material type per filament |
PLA, PETG, ABS
|
| Filament Length | Length of filament used (mm) | 1229.28mm |
| Filament Weight | Weight of filament used (g) | 3.73g |
| Filament Density | Material density (g/cm³) | 1.26 |
| Filament Color | Hex color code | #FF5733 |
| Total Weight | Combined weight of all filaments | 17.96g |
For multi-material prints (e.g., using an AMS), the parser captures data for each filament individually and displays them in a collapsible table with color swatches.
- Open the Model Details drawer for any model
- Scroll to the G-code Analysis section
- Click Upload G-code or drag-and-drop a file
- The metadata will be parsed and displayed immediately
If G-code was previously saved alongside a model, you can re-analyze it:
- Open the Model Details drawer
- In the G-code section, click Re-analyze
- The file will be re-parsed with the latest parser
G-code processing supports two storage modes, configurable in Settings:
- Extracts metadata from the uploaded file
- Does not save the G-code file to disk
- Metadata is stored in the model's
-munchie.jsonfile
- Saves the G-code file alongside the model
- Adds the file path to
related_filesin metadata - Preserves
.gcode.3mfarchives in their original binary format - Plain
.gcodefiles are saved as UTF-8 text
When using "Save and Link" mode and a G-code file already exists, a confirmation dialog is displayed to confirm overwriting.
BambuStudio format uses semicolon-separated values for material types and comma-separated values for numeric data:
; BambuStudio 2.1.0
;total filament length [mm] : 1229.28,2893.34
;total filament weight [g] : 3.73,8.77
;filament_type = PLA;PETG
;filament_density: 1.26,1.27
;filament_colour = #FF5733;#33FF57
; model printing time: 3h 6m 5s; total estimated time: 3h 13m 52sStandard slicer format:
;FLAVOR:Marlin
;TIME:53473
;Filament used: 22.4m
;Layer height: 0.2For Cura-format files, filament length is converted from meters to millimeters, and weight is estimated using the formula below.
G-code metadata is stored in the gcodeData field of the model's -munchie.json file:
{
"name": "My Model",
"gcodeData": {
"printTime": "3h 14m",
"filaments": [
{
"type": "PLA",
"length": "1229.28mm",
"weight": "3.73g",
"density": "1.26",
"color": "#FF5733"
},
{
"type": "PETG",
"length": "2893.34mm",
"weight": "8.77g",
"density": "1.27",
"color": "#33FF57"
}
],
"totalFilamentWeight": "12.50g",
"gcodeFilePath": "models/my-model.gcode"
}
}For backward compatibility, the top-level printTime and filamentUsed fields are still supported but gcodeData takes precedence.
Upload and parse a G-code file.
-
Content-Type:
multipart/form-data -
Body:
-
file: G-code file (.gcodeor.gcode.3mf) -
modelFilePath: Path to the associated model's munchie.json -
modelFileUrl: Actual model file path (.3mfor.stl) -
storageMode:"parse-only"or"save-and-link" -
overwrite:"true"to force overwrite existing files -
gcodeFilePath: (Optional) Re-analyze an existing G-code file
-
{
"success": true,
"gcodeData": {
"printTime": "3h 14m",
"filaments": [...],
"totalFilamentWeight": "12.50g",
"gcodeFilePath": "path/to/saved.gcode"
},
"fileExists": false,
"warnings": []
}{
"success": false,
"fileExists": true,
"existingPath": "models/my-model.gcode"
}Print times are normalized to a human-readable format:
| Input (seconds) | Output |
|---|---|
| 45 | 45s |
| 90 | 1m 30s |
| 3661 |
1h 2m (rounds up if seconds present) |
When hours are present, seconds are omitted and minutes are rounded up if there were any leftover seconds.
If weight is not provided in the G-code but length is available, weight is estimated using the cylinder volume formula:
Volume (mm³) = π × (diameter/2)² × length
Volume (cm³) = Volume (mm³) / 1000
Weight (g) = Volume (cm³) × density
Default values:
- Filament diameter: 1.75mm
- PLA density: 1.24 g/cm³
The parser searches for G-code files in the following priority order:
-
Metadata/plate_1.gcode(most common BambuLab format) -
Metadata/plate_N.gcode(other plate files) - Root-level
.gcodefiles (fallback)
The parser reads the first 200 lines of the G-code file for performance. Key comment patterns are matched case-insensitively:
| Pattern | Data Extracted |
|---|---|
total estimated time: |
Print time (BambuStudio) |
total filament length [mm] : |
Filament lengths |
total filament weight [g] : |
Filament weights |
filament_type = |
Material types |
filament_density: |
Material densities |
filament_colour = |
Hex color codes |
;TIME: |
Print time in seconds (Cura) |
;Filament used: |
Length in meters (Cura) |
- Ensure the G-code file has metadata comments in the first 200 lines
- Check that comment formatting matches supported slicer formats
- For
.gcode.3mffiles, verify the G-code is inMetadata/plate_1.gcode
If only length is provided, weight is automatically estimated. For accurate weights:
- Use a slicer that outputs weight data (BambuStudio)
- Or ensure filament density is specified in slicer settings
After updating 3D Model Muncher, you can re-analyze existing G-code files to take advantage of parser improvements:
- Open the model's details panel
- Click Re-analyze in the G-code section
- Updated metadata will be extracted and saved