Advanced Examples
Complex, production-ready GScript programs demonstrating advanced features and real-world workflows.
Multi-Operation Fixture Plate
A complete fixture plate with facing, pocketing, and mounting holes - demonstrating a typical production workflow.
Use case: Creating custom fixture plates for CNC work holding
meta:
part_name: "fixture-plate-100x80"
material: "aluminum-6061"
units: mm
origin: {x:0, y:0, z:0}
tooling:
# Large tool for facing
- id: face-mill-12mm
type: endmill
diameter: 12.0
max_rpm: 8000
flutes: 4
# Medium tool for pockets
- id: endmill-8mm
type: endmill
diameter: 8.0
max_rpm: 10000
flutes: 3
# Finishing tool for detail
- id: endmill-4mm
type: endmill
diameter: 4.0
max_rpm: 12000
flutes: 2
# Drill for mounting holes
- id: drill-5mm
type: drill
diameter: 5.0
max_rpm: 5000
setup:
stock: {x:110, y:90, z:12}
safe_height: 8
program:
# Step 1: Face top surface for flatness
- op: face
tool: face-mill-12mm
depth: 1.0
pass_depth: 0.5
feed: 1200
bounds: rect(0, 0, 100, 80)
stepover: 0.7
# Step 2: Rough pocket with larger tool
- op: pocket
tool: endmill-8mm
bounds: rect(15, 15, 70, 50)
depth: 6.0
pass_depth: 2.0
feed: 900
strategy: spiral
stepover: 0.6
# Step 3: Finish pocket walls with smaller tool
- op: contour
tool: endmill-4mm
depth: 6.0
pass_depth: 1.5
feed: 600
closed: true
path:
- {x:15, y:15, z:0}
- {x:85, y:15, z:0}
- {x:85, y:65, z:0}
- {x:15, y:65, z:0}
# Step 4: Create smaller detail pockets
- op: pocket
tool: endmill-4mm
bounds: rect(25, 25, 15, 15)
depth: 3.0
pass_depth: 1.0
feed: 700
strategy: climb
- op: pocket
tool: endmill-4mm
bounds: rect(60, 25, 15, 15)
depth: 3.0
pass_depth: 1.0
feed: 700
strategy: climb
# Step 5: Drill mounting holes in corners
- op: drill
tool: drill-5mm
depth: 10.0
feed: 300
locations:
- {x:5, y:5, z:0}
- {x:95, y:5, z:0}
- {x:5, y:75, z:0}
- {x:95, y:75, z:0}
# Step 6: Drill center locating hole
- op: drill
tool: drill-5mm
depth: 8.0
feed: 300
locations:
- {x:50, y:40, z:0}
export:
backend: grbl
optimization: O1
post_process: trueKey concepts:
- Progressive tooling: Large → medium → small tools
- Roughing vs finishing: Rough with larger tool, finish with smaller
- Multiple operation types: Face, pocket, contour, drill
- Strategic ordering: Face first, drill last
- Optimization: Using appropriate stepover and pass depth per tool
Estimated time: ~15-20 minutes Material removal: ~12,000 mm³
Nested Pockets with Islands
Create complex geometry with material islands inside pockets.
Use case: Parts with internal features, weight reduction pockets
meta:
part_name: "nested-pocket-demo"
material: "aluminum"
units: mm
tooling:
- id: roughing-mill
type: endmill
diameter: 8.0
max_rpm: 10000
- id: finishing-mill
type: endmill
diameter: 4.0
max_rpm: 12000
setup:
stock: {x:120, y:100, z:15}
safe_height: 8
program:
# Outer pocket (large area)
- op: pocket
tool: roughing-mill
bounds: rect(10, 10, 100, 80)
depth: 8.0
pass_depth: 2.0
feed: 1000
strategy: spiral
stepover: 0.5
# Inner detail pockets (avoiding "islands")
- op: pocket
tool: finishing-mill
bounds: rect(30, 30, 20, 20)
depth: 12.0
pass_depth: 1.5
feed: 700
strategy: climb
- op: pocket
tool: finishing-mill
bounds: rect(70, 30, 20, 20)
depth: 12.0
pass_depth: 1.5
feed: 700
strategy: climb
- op: pocket
tool: finishing-mill
bounds: rect(30, 60, 20, 20)
depth: 12.0
pass_depth: 1.5
feed: 700
strategy: climb
- op: pocket
tool: finishing-mill
bounds: rect(70, 60, 20, 20)
depth: 12.0
pass_depth: 1.5
feed: 700
strategy: climb
# Profile the outer edge for clean walls
- op: contour
tool: finishing-mill
depth: 8.0
pass_depth: 2.0
feed: 600
closed: true
path:
- {x:10, y:10, z:0}
- {x:110, y:10, z:0}
- {x:110, y:90, z:0}
- {x:10, y:90, z:0}
export:
backend: grbl
optimization: O1
post_process: trueTechnique: Create nested features by:
- Rough outer pocket first
- Mill inner features at different depths
- Finish outer walls last
Optimization Comparison
Demonstrating the impact of optimization levels on output.
meta:
part_name: "optimization-demo"
material: "aluminum"
units: mm
tooling:
- id: endmill-6mm
type: endmill
diameter: 6.0
max_rpm: 12000
setup:
stock: {x:50, y:50, z:10}
safe_height: 5
program:
# Simple face operation - watch how optimization affects output
- op: face
tool: endmill-6mm
depth: 2.0
pass_depth: 0.5
feed: 800
bounds: rect(0, 0, 50, 50)
# Pocket with strategic moves
- op: pocket
tool: endmill-6mm
bounds: rect(10, 10, 30, 30)
depth: 5.0
pass_depth: 1.0
feed: 700
strategy: spiral
export:
backend: grbl
optimization: O1 # Try O0, O1, O2, O3
post_process: trueCompile with different levels:
# No optimization
gscriptc compile optimization-demo.gscript --target grbl -O0 -o o0.gcode
# Basic optimization (default)
gscriptc compile optimization-demo.gscript --target grbl -O1 -o o1.gcode
# Compare file sizes
ls -lh o0.gcode o1.gcodeTypical results:
- O0: 450 lines, many redundant moves
- O1: 320 lines, ~30% smaller, moves merged
- O2: 250 lines, ~45% smaller, arc fitting [planned]
- O3: 200 lines, ~55% smaller, path optimized [planned]
Multi-Backend Compatibility
Single program that compiles to multiple CNC controllers.
meta:
part_name: "universal-part"
material: "aluminum"
units: mm
tooling:
- id: universal-endmill
type: endmill
diameter: 6.0
max_rpm: 12000
flutes: 2
setup:
stock: {x:80, y:60, z:10}
safe_height: 5
program:
- op: face
tool: universal-endmill
depth: 1.5
pass_depth: 0.5
feed: 1000
bounds: rect(0, 0, 80, 60)
- op: pocket
tool: universal-endmill
bounds: rect(20, 15, 40, 30)
depth: 4.0
pass_depth: 1.0
feed: 800
strategy: climb
export:
backend: grbl # Change this for different targets
post_process: trueGenerate for all backends:
# Hobby CNC (GRBL)
gscriptc compile universal.gscript --target grbl -o universal-grbl.gcode
# 3D Printer CNC mode (Marlin)
gscriptc compile universal.gscript --target marlin -o universal-marlin.gcode
# Industrial CNC (Fanuc)
gscriptc compile universal.gscript --target fanuc -o universal-fanuc.gcode
# Open-source controller (LinuxCNC)
gscriptc compile universal.gscript --target linuxcnc -o universal-linuxcnc.gcode
# Compact controller (TinyG)
gscriptc compile universal.gscript --target tinyg -o universal-tinyg.gcodeBackend differences handled automatically:
- Spindle control commands (M3/M4)
- Coordinate system setup
- Program structure (O-codes, program numbers)
- Tool offset handling
- Feed rate modes
Deep Hole Drilling with Peck
Efficient drilling of deep holes using peck cycles.
meta:
part_name: "deep-holes"
material: "steel"
units: mm
tooling:
- id: drill-8mm
type: drill
diameter: 8.0
max_rpm: 3000 # Lower speed for steel
setup:
stock: {x:100, y:100, z:40}
safe_height: 10
program:
# Deep holes require peck drilling
- op: drill
tool: drill-8mm
depth: 35.0
peck_depth: 5.0 # Retract every 5mm to clear chips
feed: 150 # Slower feed for steel
locations:
- {x:25, y:25, z:0}
- {x:75, y:25, z:0}
- {x:25, y:75, z:0}
- {x:75, y:75, z:0}
export:
backend: fanuc # Industrial controller
post_process: truePeck drilling benefits:
- Clears chips from deep holes
- Prevents drill breakage
- Better hole quality
- Safer for expensive tools
Generated G-code includes:
- G83 peck drill cycles (where supported)
- Automatic retract and re-entry
- Proper dwell times
Production Part Template
A template structure for production parts with comprehensive metadata.
meta:
part_name: "production-part-001"
material: "aluminum-6061-t6"
units: mm
origin: {x:0, y:0, z:0}
# Additional metadata in comments:
# Customer: ACME Corp
# Part Number: P-12345
# Revision: A
# Operator: Initials required
# Setup: Vise, soft jaws, 10mm stop
tooling:
# Document tool library references
- id: roughing-endmill
type: endmill
diameter: 10.0
max_rpm: 10000
flutes: 3
# Tool library: HSS-010-3F
- id: finishing-endmill
type: endmill
diameter: 6.0
max_rpm: 12000
flutes: 4
# Tool library: CARB-006-4F
- id: spot-drill
type: drill
diameter: 3.0
max_rpm: 4000
# Tool library: SPOT-003
- id: drill-6mm
type: drill
diameter: 6.0
max_rpm: 4000
# Tool library: DRILL-006-HSS
setup:
stock: {x:150, y:100, z:25}
safe_height: 10
# Setup notes:
# - Z-zero on top of stock
# - X/Y zero front left corner
# - Check soft jaw clearance
program:
# Operation 1: Face top surface
- op: face
tool: roughing-endmill
depth: 0.5
pass_depth: 0.5
feed: 1500
bounds: rect(0, 0, 150, 100)
# Leave 0.5mm for finish pass if needed
# Operation 2: Rough main pocket
- op: pocket
tool: roughing-endmill
bounds: rect(20, 15, 110, 70)
depth: 15.0
pass_depth: 3.0
feed: 1200
strategy: spiral
stepover: 0.6
# Rough to depth, leave 0.5mm for finish
# Operation 3: Finish pocket walls
- op: contour
tool: finishing-endmill
depth: 15.0
pass_depth: 3.0
feed: 800
closed: true
path:
- {x:20, y:15, z:0}
- {x:130, y:15, z:0}
- {x:130, y:85, z:0}
- {x:20, y:85, z:0}
# Operation 4: Spot drill mounting holes
- op: drill
tool: spot-drill
depth: 2.0
feed: 200
locations:
- {x:10, y:10, z:0}
- {x:140, y:10, z:0}
- {x:10, y:90, z:0}
- {x:140, y:90, z:0}
# Operation 5: Drill through holes
- op: drill
tool: drill-6mm
depth: 22.0
feed: 250
peck_depth: 5.0
locations:
- {x:10, y:10, z:0}
- {x:140, y:10, z:0}
- {x:10, y:90, z:0}
- {x:140, y:90, z:0}
export:
backend: grbl
optimization: O1
post_process: true
# Quality control:
# - Verify dimensions after op 2
# - Check hole positions before op 5
# - Deburr all edges after completionProduction features:
- Comprehensive metadata and documentation
- Tool library references
- Setup instructions in comments
- QC checkpoints noted
- Progressive roughing to finishing
- Spot drill before final drill
Workflow Tips
Testing New Programs
# 1. Validate first
gscriptc validate advanced-program.gscript
# 2. Compile with no optimization for debugging
gscriptc compile advanced-program.gscript --target grbl -O0 -o test.gcode
# 3. Simulate before running
gscriptc simulate test.gcode --summary
# 4. Estimate time
gscriptc estimate advanced-program.gscript
# 5. When confident, compile with optimization
gscriptc compile advanced-program.gscript --target grbl -O1 -o final.gcodeMulti-Operation Strategy
- Face first - Establish reference surface
- Rough with large tools - Remove bulk material quickly
- Finish with small tools - Final dimensions and surface finish
- Drill last - Avoid stress concentrations during milling
Tool Selection
- Roughing: 50-70% stepover, larger diameter, aggressive depth
- Finishing: 25-40% stepover, smaller diameter, shallow depth
- Drilling: Spot drill first, proper speeds for material
Next Steps
- Real-World Projects - Complete production examples
- Basic Examples - Start simpler if these are complex
- Language Reference - Understand all syntax options
- CLI Commands - Master the toolchain
Download Examples
All examples are in the repository.
Try them:
cd gscript-core/examples
gscriptc compile widget-plate.gscript --target grbl -o widget.gcode
gscriptc simulate widget.gcode --summary