Skip to content

G‐code Analysis and Processing

Rob Sturgill edited this page Nov 29, 2025 · 1 revision

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.

Table of Contents


Supported Formats

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 .gcode.3mf Files

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.


Extracted Metadata

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

Multi-Filament Support

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.


How to Upload G-code

Method 1: Model Details Panel

  1. Open the Model Details drawer for any model
  2. Scroll to the G-code Analysis section
  3. Click Upload G-code or drag-and-drop a file
  4. The metadata will be parsed and displayed immediately
gcode-upload

Method 2: Re-analyze Existing G-code

If G-code was previously saved alongside a model, you can re-analyze it:

  1. Open the Model Details drawer
  2. In the G-code section, click Re-analyze
  3. The file will be re-parsed with the latest parser
gcode-processed

Storage Modes

G-code processing supports two storage modes, configurable in Settings:

gcode-settings

Parse Only (Default)

  • Extracts metadata from the uploaded file
  • Does not save the G-code file to disk
  • Metadata is stored in the model's -munchie.json file

Save and Link

  • Saves the G-code file alongside the model
  • Adds the file path to related_files in metadata
  • Preserves .gcode.3mf archives in their original binary format
  • Plain .gcode files are saved as UTF-8 text

Overwrite Behavior

When using "Save and Link" mode and a G-code file already exists, a confirmation dialog is displayed to confirm overwriting.


Supported Slicers

BambuStudio / Orca Slicer

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 52s

Cura / PrusaSlicer

Standard slicer format:

;FLAVOR:Marlin
;TIME:53473
;Filament used: 22.4m
;Layer height: 0.2

For Cura-format files, filament length is converted from meters to millimeters, and weight is estimated using the formula below.


Data Storage

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"
  }
}

Legacy Compatibility

For backward compatibility, the top-level printTime and filamentUsed fields are still supported but gcodeData takes precedence.


API Reference

POST /api/parse-gcode

Upload and parse a G-code file.

Request

  • Content-Type: multipart/form-data
  • Body:
    • file: G-code file (.gcode or .gcode.3mf)
    • modelFilePath: Path to the associated model's munchie.json
    • modelFileUrl: Actual model file path (.3mf or .stl)
    • storageMode: "parse-only" or "save-and-link"
    • overwrite: "true" to force overwrite existing files
    • gcodeFilePath: (Optional) Re-analyze an existing G-code file

Response

{
  "success": true,
  "gcodeData": {
    "printTime": "3h 14m",
    "filaments": [...],
    "totalFilamentWeight": "12.50g",
    "gcodeFilePath": "path/to/saved.gcode"
  },
  "fileExists": false,
  "warnings": []
}

Error Response (File Exists)

{
  "success": false,
  "fileExists": true,
  "existingPath": "models/my-model.gcode"
}

Technical Details

Time Normalization

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.

Weight Estimation

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³

G-code Extraction from .gcode.3mf

The parser searches for G-code files in the following priority order:

  1. Metadata/plate_1.gcode (most common BambuLab format)
  2. Metadata/plate_N.gcode (other plate files)
  3. Root-level .gcode files (fallback)

Parser Implementation

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)

Troubleshooting

G-code Not Parsing

  1. Ensure the G-code file has metadata comments in the first 200 lines
  2. Check that comment formatting matches supported slicer formats
  3. For .gcode.3mf files, verify the G-code is in Metadata/plate_1.gcode

Missing Weight Data

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

Re-analyzing After Parser Updates

After updating 3D Model Muncher, you can re-analyze existing G-code files to take advantage of parser improvements:

  1. Open the model's details panel
  2. Click Re-analyze in the G-code section
  3. Updated metadata will be extracted and saved

See Also

Clone this wiki locally