Skip to content

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

yaml
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: true

Key concepts:

  • Single tool definition
  • Multiple drill locations
  • Simple rectangular stock

Download example


Face Milling

Surface milling to create a flat, finished surface.

Use case: Facing stock, creating flat reference surfaces, removing material evenly

yaml
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: true

Key concepts:

  • Using endmills for surface operations
  • Multiple passes with pass_depth
  • bounds defines 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

Download example


Pocket Milling

Clearing a rectangular pocket or recess.

Use case: Creating recesses, clearances, pockets for inserts

yaml
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: true

Key concepts:

  • Pocket operation clears material inside bounds
  • strategy controls cutting pattern (climb, conventional, spiral)
  • Pocket starts at (20,20) and is 60mm x 40mm
  • Tool makes 3 passes at 1mm depth each

Strategies:

  • climb: Climb milling (recommended for most materials)
  • conventional: Conventional milling
  • spiral: Spiral pattern from outside to center

Download example


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

yaml
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: true

Key concepts:

  • Multiple tools in tooling block
  • Operations execute in order
  • Each operation references its required tool
  • Comments (with #) help document workflow
  • Tool changes happen automatically between operations

Workflow:

  1. Face with 12mm endmill - removes 1mm from top surface
  2. Pocket with 6mm endmill - creates 5mm deep pocket in center
  3. Drill with 4mm drill - adds mounting holes in corners

Download example


Comparing Operations

When to Use Each Operation

OperationPurposeTypical ToolsBest For
faceSurface millingLarge endmills (10-20mm)Flat surfaces, stock prep
pocketMaterial removalMedium endmills (4-12mm)Recesses, clearances
drillHole makingDrill bitsThrough holes, pilot holes
contourEdge cuttingSmall 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:

yaml
setup:
  stock: {x:200, y:150, z:20}  # Larger stock

Add More Holes

Extend drill locations:

yaml
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):

yaml
meta:
  material: "wood"  # or "steel", "plastic", etc.

Adjust Feeds

Slower for harder materials:

yaml
program:
  - op: face
    feed: 600  # Slower feed for steel

Next Steps

Ready for more complex examples?

Download All Examples

All examples are available in the examples directory of the repository.

Clone the repo to try them:

bash
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

Released under the Apache License 2.0