Skip to content

Parallel-7/slicer-meta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Slicer Meta Parser

A TypeScript library for parsing metadata from 3D printing slicer files

npm version Node.js Version TypeScript License


Supported File Formats

File Format Extension Description
G-Code .gcode, .g Standard G-Code files from various slicers
GX Binary .gx FlashForge binary format with embedded thumbnails
3MF Archive .3mf ZIP-based 3D manufacturing format with metadata

Supported Slicers

Slicer Detection Metadata Support
FlashPrint Header-based Full support for printer model, filament type, timestamps
Orca-FlashForge Header-based Advanced metadata including detailed filament tracking
OrcaSlicer Header-based Block-based metadata with Base64 thumbnails
Legacy GX Format-based Binary format with embedded G-Code parsing

Feature Coverage

Feature G-Code GX Binary 3MF Archive
Slicer Detection Yes Yes Yes
Version & Timestamp Yes Yes Yes
Print Time (ETA) Yes Yes Yes
Filament Usage (mm/g) Yes Yes Yes
Filament Type Yes Yes Yes
Filament Color No No Yes
Multiple Filaments Limited Limited Yes
Printer Model Yes Yes Yes
Thumbnail Extraction Base64 Binary Base64
Support Detection No No Yes
Model File Names No No Yes
Plate Images No No Yes

Parsing Capabilities

Capability Description
Auto-Detection Automatically detects file type based on extension
Universal Interface Single function handles all supported formats
Slicer Identification Determines slicer type from file headers
Metadata Extraction Parses comments and embedded metadata blocks
Thumbnail Processing Extracts and decodes Base64 encoded images
Unit Conversion Converts filament usage to meters automatically
Filtered Results Shows only filaments actually used in print
Binary Parsing Handles GX binary format with embedded G-Code
Archive Processing Unzips and parses 3MF container structure

Installation

Configure npm to use the GitHub Packages registry by adding the following to a .npmrc file in your project root:

@parallel-7:registry=https://npm.pkg.github.com/

Install the package:

npm install @parallel-7/slicer-meta

You will need to authenticate with GitHub Packages to download private packages.


Basic Usage

The primary method for parsing slicer files is the parseSlicerFile function, which automatically handles all supported file formats:

import { parseSlicerFile } from '@parallel-7/slicer-meta';

async function main() {
  try {
    const filePath = 'path/to/your/file.gcode';
    const metadata = await parseSlicerFile(filePath);

    console.log('Slicer Info:', metadata.slicer);
    console.log('File Info:', metadata.file);

    if (metadata.threeMf) {
      console.log('3MF Specific Info:', metadata.threeMf);
    }
  } catch (error) {
    console.error('Failed to parse file:', error);
  }
}

main();

Advanced Usage Examples

Parsing G-Code Files

import { GCodeParser } from '@parallel-7/slicer-meta';

async function parseGCode() {
  const parser = new GCodeParser();
  await parser.parse('path/to/your/file.gcode');

  console.log('Slicer Info:', parser.slicerInfo);
  console.log('File Info:', parser.fileInfo);
  console.log('Print ETA:', parser.slicerInfo?.printEta);
  console.log('Filament Used:', parser.fileInfo?.filamentUsedMM, 'mm');
}

parseGCode();

Parsing 3MF Archives

import { ThreeMfParser } from '@parallel-7/slicer-meta';

function parse3MF() {
  const parser = new ThreeMfParser();
  parser.parse('path/to/your/file.3mf');

  console.log('Printer Model:', parser.printerModelId);
  console.log('Support Used:', parser.supportUsed);
  console.log('Model Files:', parser.fileNames);
  console.log('Filaments:', parser.filaments);

  if (parser.plateImage) {
    console.log('Plate thumbnail available');
  }
}

parse3MF();

Parsing GX Binary Files

import { GXParser } from '@parallel-7/slicer-meta';

async function parseGX() {
  const parser = new GXParser();
  await parser.parse('path/to/your/file.gx');

  console.log('Printer Model:', parser.fileInfo?.printerModel);
  console.log('Filament Type:', parser.fileInfo?.filamentType);

  if (parser.fileInfo?.thumbnail) {
    console.log('Thumbnail extracted from binary format');
  }
}

parseGX();

Working with Multiple Filaments

import { parseSlicerFile } from '@parallel-7/slicer-meta';

async function analyzeFilaments() {
  const metadata = await parseSlicerFile('path/to/multi-filament.3mf');

  if (metadata.file?.filaments) {
    metadata.file.filaments.forEach((filament, index) => {
      console.log(`Filament ${index + 1}:`);
      console.log(`  Type: ${filament.type}`);
      console.log(`  Color: ${filament.color}`);
      console.log(`  Used: ${filament.usedM}m (${filament.usedG}g)`);
    });
  }
}

analyzeFilaments();

Available Parsers

Parser File Types Use Case
GCodeParser .gcode, .g Universal G-Code parser with auto-detection
FlashPrintParser .gcode FlashPrint-specific G-Code files
OrcaFlashForgeParser .gcode Orca Slicer / Orca-FlashForge files
GXParser .gx FlashForge binary format files
ThreeMfParser .3mf 3MF archive files (optimized for Orca Slicer)

Return Data Structure

Slicer Metadata

Field Type Description
slicerName string Name of the slicer software
slicerVersion string Version of the slicer
sliceDate string Date when file was sliced
sliceTime string Time when file was sliced
printEta string | null Estimated print time
slicer SlicerType Enum identifying slicer type

File Metadata

Field Type Description
thumbnail string | null Base64 encoded thumbnail image
filamentUsedMM number Total filament used in millimeters
filamentUsedG number Total filament used in grams
filamentType string Primary filament material type
printerModel string Target printer model
sliceSoft SlicerType Slicer type enum
filaments FilamentInfo[] Array of detailed filament info

3MF Specific Data

Field Type Description
printerModelId string Printer model identifier
supportUsed boolean Whether support structures are used
fileNames string[] Array of model file names in archive
filaments FilamentInfo[] Detailed per-filament information
plateImage string | null Base64 encoded plate preview image

About

Cross Platform API in TypeScript for extracting metadata from G-Code/3MF files

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors 3

  •  
  •  
  •  

Languages