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:
- Design your job with layers and operations
- Preview in 3D to verify (optional)
- File Export G-code (or Ctrl+E)
- Choose save location and filename
- 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¶
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:
See Macros & Hooks for details.
File Naming¶
Recommended Naming Conventions¶
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:
- Reduce raster DPI:
- 300-400 DPI is usually sufficient
-
Higher DPI doesn't improve quality beyond laser resolution
-
Simplify vector paths:
- Reduce number of nodes
-
Use path simplification tools
-
Lower precision:
- Precision 2 instead of 3 significantly reduces size
-
Quality difference is negligible
-
Split large jobs:
- Break into multiple files
-
Run sequentially
-
Reduce overscan:
- Less overscan = fewer extra moves
- Balance quality vs file size
Verifying G-code¶
Preview Before Exporting¶
Always preview your job:
- 3D Preview - Check layer order and operations
- Simulation Mode (F7) - Verify execution timing
- Frame Job - Test boundaries on machine
Checking Exported G-code¶
Manual inspection:
- Open in text editor to review
- Check header - Verify setup commands
- Check footer - Ensure laser turns off
- 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:
- Connect to machine (Machine Connect)
- Click Run Job or Machine Run
- G-code generated and streamed to controller
Advantages: - No intermediate file needed - Immediate execution - Real-time monitoring
Via File¶
Export then load to controller:
- Export G-code (File Export)
- Transfer to controller:
- SD card (if controller supports)
- USB flash drive
- 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:
- Simplify the job - Very complex jobs may time out
- Check for errors - Review console/logs for error messages
- Reduce raster resolution - Lower DPI
- Close other applications - Free up system resources
- Save project first - Ensure work isn't lost
G-code Has Errors¶
Problem: Exported G-code contains invalid commands or values.
Diagnosis:
- Check operation settings - Invalid power/speed values
- Review transformers - Broken or misconfigured transformers
- Test simple job - Export a basic square to isolate issue
- 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:
- Wrong dialect - GRBL vs other firmware
- Unsupported commands - Custom commands not recognized
- File too large - Exceeds controller memory
- Filename issues - Spaces or special characters
- 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:
- Reposition job within bounds
- Scale down if too large
- Check machine dimensions are correctly configured
- 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
Related Pages¶
- Importing Files - Getting designs into Rayforge
- Supported Formats - File format details
- G-code Dialects - Dialect differences
- Macros & Hooks - Customizing output
- Simulation Mode - Preview before export