Basic Examples
Learn GScript fundamentals through simple, working examples. Each example demonstrates a core concept you can build upon.
Simple Drilling Pattern
The most basic GScript program - drilling four holes in a square pattern.
Use case: Mounting holes, bolt patterns, alignment pins
meta:
part_name: "drill-pattern"
material: "aluminum"
units: mm
tooling:
- id: drill1
type: drill
diameter: 5.0
max_rpm: 5000
setup:
stock: {x:50, y:50, z:10}
safe_height: 5
program:
- op: drill
tool: drill1
locations:
- {x:10, y:10, z:0}
- {x:40, y:10, z:0}
- {x:10, y:40, z:0}
- {x:40, y:40, z:0}
depth: 5
feed: 300
export:
backend: grbl
post_process: trueKey concepts:
- Single tool definition
- Multiple drill locations
- Simple rectangular stock
Face Milling
Surface milling to create a flat, finished surface.
Use case: Facing stock, creating flat reference surfaces, removing material evenly
meta:
part_name: "face-test"
material: "steel"
units: mm
origin: {x:0, y:0, z:0}
tooling:
- id: endmill-12mm
type: endmill
diameter: 12.0
max_rpm: 10000
setup:
stock: {x:80, y:60, z:8}
safe_height: 5
program:
- op: face
tool: endmill-12mm
depth: 2.0
pass_depth: 0.5
feed: 1200
bounds: rect(0, 0, 80, 60)
export:
backend: grbl
profile: null
post_process: trueKey concepts:
- Using endmills for surface operations
- Multiple passes with
pass_depth boundsdefines the area to mill- Larger tools for facing operations
Parameters explained:
depth: 2.0- Total material to remove (2mm)pass_depth: 0.5- Remove 0.5mm per pass (4 passes total)feed: 1200- Feed rate in mm/min
Pocket Milling
Clearing a rectangular pocket or recess.
Use case: Creating recesses, clearances, pockets for inserts
meta:
part_name: "pocket-test"
material: "aluminum"
units: mm
origin: {x:0, y:0, z:0}
tooling:
- id: endmill-6mm
type: endmill
diameter: 6.0
max_rpm: 12000
setup:
stock: {x:100, y:80, z:10}
safe_height: 5
program:
- op: pocket
tool: endmill-6mm
depth: 3.0
pass_depth: 1.0
feed: 800
bounds: rect(20, 20, 60, 40)
strategy: climb
export:
backend: grbl
profile: null
post_process: trueKey concepts:
- Pocket operation clears material inside bounds
strategycontrols cutting pattern (climb, conventional, spiral)- Pocket starts at
(20,20)and is60mm x 40mm - Tool makes 3 passes at 1mm depth each
Strategies:
climb: Climb milling (recommended for most materials)conventional: Conventional millingspiral: Spiral pattern from outside to center
Multi-Tool Program
Combining multiple operations with different tools - the most common real-world pattern.
Use case: Complete part machining with roughing, pocketing, and drilling
meta:
part_name: "multi-tool-test"
material: "aluminum"
units: mm
origin: {x:0, y:0, z:0}
tooling:
- id: face-mill
type: endmill
diameter: 12.0
max_rpm: 8000
- id: pocket-mill
type: endmill
diameter: 6.0
max_rpm: 12000
- id: drill-bit
type: drill
diameter: 4.0
max_rpm: 5000
setup:
stock: {x:100, y:100, z:15}
safe_height: 10
program:
# Step 1: Face the top surface
- op: face
tool: face-mill
depth: 1.0
pass_depth: 0.5
feed: 1000
bounds: rect(0, 0, 100, 100)
# Step 2: Mill a pocket
- op: pocket
tool: pocket-mill
depth: 5.0
pass_depth: 1.5
feed: 800
bounds: rect(20, 20, 40, 40)
strategy: spiral
# Step 3: Drill mounting holes
- op: drill
tool: drill-bit
depth: 8.0
feed: 300
locations:
- {x:10, y:10, z:0}
- {x:90, y:10, z:0}
- {x:10, y:90, z:0}
- {x:90, y:90, z:0}
export:
backend: grbl
profile: null
post_process: trueKey concepts:
- Multiple tools in
toolingblock - Operations execute in order
- Each operation references its required tool
- Comments (with
#) help document workflow - Tool changes happen automatically between operations
Workflow:
- Face with 12mm endmill - removes 1mm from top surface
- Pocket with 6mm endmill - creates 5mm deep pocket in center
- Drill with 4mm drill - adds mounting holes in corners
Comparing Operations
When to Use Each Operation
| Operation | Purpose | Typical Tools | Best For |
|---|---|---|---|
| face | Surface milling | Large endmills (10-20mm) | Flat surfaces, stock prep |
| Material removal | Medium endmills (4-12mm) | Recesses, clearances | |
| drill | Hole making | Drill bits | Through holes, pilot holes |
| contour | Edge cutting | Small endmills (2-6mm) | Part outlines, profiles |
Operation Comparison
Face vs Pocket:
- Face mills the entire area
- Pocket mills a rectangular region
- Face typically uses larger tools
- Pocket can use different clearing strategies
Drill vs Pocket:
- Drill is for specific point locations
- Pocket clears an entire area
- Drill is faster for holes
- Pocket is better for rectangular recesses
Try These Modifications
Make It Bigger
Change stock dimensions:
setup:
stock: {x:200, y:150, z:20} # Larger stockAdd More Holes
Extend drill locations:
locations:
- {x:10, y:10, z:0}
- {x:10, y:90, z:0}
- {x:50, y:50, z:0} # Center hole
- {x:90, y:10, z:0}
- {x:90, y:90, z:0}Change Material
Update material (for documentation):
meta:
material: "wood" # or "steel", "plastic", etc.Adjust Feeds
Slower for harder materials:
program:
- op: face
feed: 600 # Slower feed for steelNext Steps
Ready for more complex examples?
- Advanced Examples - Multi-operation workflows, optimization
- Real-World Projects - Complete production-ready programs
- Language Reference - Full syntax documentation
- Operations Guide - Detailed operation parameters
Download All Examples
All examples are available in the examples directory of the repository.
Clone the repo to try them:
git clone https://github.com/Parametrix-Labs/gscript-core.git
cd gscript-core/examples
# Compile any example
gscriptc compile simple-drill.gscript --target grbl -o output.gcode