Skip to content

Exporting G-code

This page explains how to export G-code from Rayforge and customize export settings for your machine.

Quick Export

Generate G-code for your job:

  1. Design your job with layers and operations
  2. Preview in 3D to verify (optional)
  3. File Export G-code (or Ctrl+E)
  4. Choose save location and filename
  5. Click Save

Your G-code file is now ready to send to your machine!


Export Methods

Method 1: File Menu

File Export G-code (Ctrl+E)

  • Opens file save dialog
  • Choose location and filename
  • G-code generated and saved

Method 2: Send to Machine

Machine Run Job or click Run button

  • G-code generated in memory
  • Sent directly to connected machine
  • Optionally save to file as well

Method 3: Command Line

# Export from command line (if supported)
rayforge --export output.gcode input.svg

G-code Output

What's Included

Generated G-code contains:

Header: - Comments with job information - Setup commands (units, positioning mode) - Job start hooks (if configured)

Body: - Toolpath commands for each layer - Layer start/end hooks - Workpiece start/end hooks - Power control commands - Feed rate specifications

Footer: - Job end hooks (if configured) - Return to origin (if configured) - Laser off, air assist off

Example G-code Structure

; ==========================================
; Generated by Rayforge
; Job: my-project
; Date: 2025-10-03 14:30:00
; ==========================================

; Setup
G21                    ; Millimeters
G90                    ; Absolute positioning
M5                     ; Laser off

; Job Start Hook (if configured)
$H                     ; Home machine
M8                     ; Air assist on

; Layer 1: Engrave Layer
; Layer Start Hook
G0 X10.000 Y10.000    ; Rapid move to start
M3 S500               ; Laser on at power 500
G1 X50.000 F3000      ; Cut to X50 at 3000mm/min
; ... (more engraving commands)
; Layer End Hook

; Layer 2: Cut Layer
; Layer Start Hook
G0 X10.000 Y10.000
M3 S900               ; Laser on at power 900
G1 X50.000 F500       ; Cut at slower speed
; ... (more cutting commands)
; Layer End Hook

; Job End Hook (if configured)
M5                     ; Laser off
M9                     ; Air assist off
G0 X0 Y0              ; Return to origin

; End of job

Export Settings

General Settings

Access: Settings Machine G-code Settings

Setting Description Values Default
Precision Decimal places for coordinates 0-5 3
Dialect G-code flavor GRBL, etc. GRBL
Max Speed Maximum travel speed (mm/min) Positive number 3000
Max Cut Speed Maximum cutting speed (mm/min) Positive number 1000

Coordinate Precision

Precision determines how many decimal places are used for coordinates.

Examples:

Precision Example Output Precision Level
0 G0 X50 Y100 1mm (very coarse)
1 G0 X50.5 Y100.2 0.1mm
2 G0 X50.53 Y100.27 0.01mm
3 G0 X50.532 Y100.271 0.001mm (recommended)
4 G0 X50.5320 Y100.2714 0.0001mm (usually unnecessary)

Recommendations:

  • Precision 3 (default): Best for most work (0.001mm = 1 micron)
  • Precision 2: Faster processing, still very accurate
  • Precision 4+: Unnecessary (laser spot size is typically 0.1-0.3mm)

Trade-offs:

  • Higher precision: Larger file sizes, longer processing
  • Lower precision: Faster, smaller files, but less smooth curves

G-code Dialect

Dialect determines which G-code commands and syntax to use.

Supported dialects:

  • GRBL (default) - For GRBL firmware controllers
  • Other dialects may be added in future versions

See G-code Dialects for details.


Customizing Output

Machine Configuration

Machine settings affect G-code generation:

Settings Machine Profile

Setting Effect on G-code
Work Area Size Warns if job exceeds bounds
Y-Axis Direction Inverts Y coordinates if needed
Max Speeds Enforces speed limits

Hooks and Macros

Inject custom G-code at specific points:

Settings Machine Hooks

Available hooks: - Job Start - Beginning of file - Job End - End of file - Layer Start - Before each layer - Layer End - After each layer - Workpiece Start - Before each workpiece - Workpiece End - After each workpiece

Example Job Start Hook:

$H          ; Home machine
G0 X0 Y0    ; Move to origin
M8          ; Air assist on

See Macros & Hooks for details.


File Naming

Good filenames:

project-name_material_date.gcode
box-3mm-ply_2025-10-03.gcode
logo-engrave_v2.nc
test-grid_CO2_50W.gcode

Include: - Project or part name - Material type/thickness (if relevant) - Date or version number - Machine or settings identifier

Avoid: - Spaces (use hyphens or underscores) - Special characters (some controllers don't support) - Very long names (>32 characters may be truncated)

Common Extensions

Extension Usage Compatibility
.gcode Most common Widely recognized
.nc Numerical Control CNC standard
.ngc NGC (Next Generation Controller) LinuxCNC, some others
.txt Plain text Universal fallback

Recommendation: Use .gcode for clarity.


File Size Considerations

Typical File Sizes

Job Type Complexity File Size
Simple cut Square or circle 1-10 KB
Logo engrave Vector paths 10-100 KB
Photo engrave Raster, 300 DPI, 1010cm 5-20 MB
Detailed cut Many small paths 100 KB - 5 MB
Large photo Raster, 500 DPI, 2020cm 50-100 MB

Large Files

Problems with very large G-code files (>50 MB):

  • Slow to load on controller
  • May exceed controller memory
  • Longer processing time
  • Transfer delays over serial

Optimization strategies:

  1. Reduce raster DPI:
  2. 300-400 DPI is usually sufficient
  3. Higher DPI doesn't improve quality beyond laser resolution

  4. Simplify vector paths:

  5. Reduce number of nodes
  6. Use path simplification tools

  7. Lower precision:

  8. Precision 2 instead of 3 significantly reduces size
  9. Quality difference is negligible

  10. Split large jobs:

  11. Break into multiple files
  12. Run sequentially

  13. Reduce overscan:

  14. Less overscan = fewer extra moves
  15. Balance quality vs file size

Verifying G-code

Preview Before Exporting

Always preview your job:

  1. 3D Preview - Check layer order and operations
  2. Simulation Mode (F7) - Verify execution timing
  3. Frame Job - Test boundaries on machine

Checking Exported G-code

Manual inspection:

  1. Open in text editor to review
  2. Check header - Verify setup commands
  3. Check footer - Ensure laser turns off
  4. Scan for errors - Look for unexpected values

G-code validators:

  • CAMotics (free) - G-code simulator
  • NCViewer (web-based) - Online G-code visualizer
  • Universal G-code Sender - Has built-in visualizer

Common issues to check:

  • Coordinates within machine bounds
  • Feed rates reasonable (not 0, not excessive)
  • Power values in valid range (0-1000 for GRBL S parameter)
  • No missing laser-off commands
  • Proper layer separation

Sending to Machine

Direct Send

From Rayforge:

  1. Connect to machine (Machine Connect)
  2. Click Run Job or Machine Run
  3. G-code generated and streamed to controller

Advantages: - No intermediate file needed - Immediate execution - Real-time monitoring

Via File

Export then load to controller:

  1. Export G-code (File Export)
  2. Transfer to controller:
  3. SD card (if controller supports)
  4. USB flash drive
  5. Serial upload via UGS or similar

Advantages: - Keep G-code for re-running jobs - Use offline controllers - Archive successful jobs

G-code Senders

Recommended senders for manual control:

  • Universal G-code Sender (UGS) - Popular, cross-platform
  • LightBurn - Full laser software (alternative to Rayforge)
  • LaserGRBL - Windows, GRBL-specific
  • bCNC - Advanced, Linux-focused

Troubleshooting Export

Export Fails or Hangs

Problem: Export process doesn't complete.

Solutions:

  1. Simplify the job - Very complex jobs may time out
  2. Check for errors - Review console/logs for error messages
  3. Reduce raster resolution - Lower DPI
  4. Close other applications - Free up system resources
  5. Save project first - Ensure work isn't lost

G-code Has Errors

Problem: Exported G-code contains invalid commands or values.

Diagnosis:

  1. Check operation settings - Invalid power/speed values
  2. Review transformers - Broken or misconfigured transformers
  3. Test simple job - Export a basic square to isolate issue
  4. Check logs - Look for warnings during generation

Solutions:

  • Fix invalid settings
  • Disable problematic transformers
  • Report bug with sample project

File Won't Load on Controller

Problem: Controller rejects or can't read the G-code file.

Possible causes:

  1. Wrong dialect - GRBL vs other firmware
  2. Unsupported commands - Custom commands not recognized
  3. File too large - Exceeds controller memory
  4. Filename issues - Spaces or special characters
  5. Line ending format - Windows vs Unix line endings

Solutions:

  • Verify correct dialect selected
  • Simplify to reduce file size
  • Rename file (no spaces, short name)
  • Convert line endings if needed (dos2unix or unix2dos)

Coordinates Out of Bounds

Problem: G-code tries to move outside machine limits.

Diagnosis:

Check the Frame feature or G-code for coordinates exceeding work area.

Solutions:

  1. Reposition job within bounds
  2. Scale down if too large
  3. Check machine dimensions are correctly configured
  4. Account for overscan - Reduces available area

Advanced Export Options

Custom Post-Processors

For advanced users, custom G-code post-processing may be possible:

Potential customizations: - Add custom headers/footers - Modify command syntax - Insert pauses or prompts - Translate to other dialects

Implementation: Currently limited; consider scripting external post-processor.

Batch Export

Export multiple projects:

Currently requires manual export of each project. Scripting batch export may be possible via command-line interface (if available).


Best Practices

Before Export

  • Preview in 3D
  • Run simulation mode
  • Check all layers enabled/disabled as intended
  • Verify operations have valid settings
  • Test frame on machine (if possible)

After Export

  • Check file size is reasonable
  • Open in text editor and spot-check
  • Validate with G-code viewer
  • Backup G-code for successful jobs
  • Name file descriptively

For Production

  • Archive successful G-code - Keep files for repeat jobs
  • Version control - Track changes to settings
  • Document settings - Note material, power, speed in filename or comments
  • Test on scrap first - Verify new exports before production runs