Back

HAAS G-code Generator Documentation

This documentation outlines the methods available through the HaasGCodeGenerator JavaScript class, allowing you to generate HAAS-compatible G-code from simple JS logic. It supports multiple tool types with parameter-based feed/speed selection.

Supported Tool Types

Each tool type will have relevant machining data for RPM and feedrate calculation depending on the selected material.

This example does the following:

Example G-code Output

This is what the JavaScript above generates. If you're unfamiliar with G-code: it's a simple language used by CNC machines. Each line is a command to move, cut, or set a state. For example, G0 means rapid move, M06 is tool change, and M30 ends the program. The JavaScript shown earlier generates these commands automatically.


  %
  O0001 (My Program)
  G17 G40 G80 G54 G20
  M06 T1
  G0 X0 Y0 Z0.5
  ... (face milling motions)
  M30
  %

Methods Reference

new HaasGCodeGenerator(programNumber, programName)REQUIRED

Constructs a generator instance. Must be called before any G-code methods can be used.

programStart()REQUIRED

Initializes the program with standard setup commands (e.g., G17 G40 G80 G54 G20).

toolChange(toolNumber)REQUIRED

Selects a tool by number and inserts the appropriate M06 and spindle commands.

startPosition(x, y)REQUIRED

Moves the tool rapidly to the starting XY location at a safe height above the part. Required before most cutting operations.

faceMill(x, y, width, length, depth, stepOver)

Generates a zigzag face milling pattern for the specified area.

drillHole(x, y, retractZ, bottomZ, peckDepth, dwell)

Performs drilling cycle at specified XY location with pecking.

tapHole(x, y, retractZ, bottomZ)

Performs a tapping cycle using calculated pitch and spindle direction.

threadMillHole(x, y, retractZ, bottomZ)

Performs circular thread milling. Requires thread direction.

polygonalFaceMill(points[], depth, stepDown, overlap)

Faces inside a closed polygon with spiral offsets.

comment(text)

Inserts a comment line into the G-code.

programEnd()REQUIRED

Closes the program with M30. Must be called to finish the G-code correctly.

Material-Specific Machining

Feeds and speeds are determined dynamically from the selected material/tool type. The internal library uses a lookup via getMachiningData(material, toolType). If not found, defaults are applied.

Tool Parameter Table

Tool Type Required Parameters Additional Notes
end_milldiameter, teethDefault tool type
face_milldiameter, teethUsed for flat facing
drilldiameterFeedrate depends on peck + dwell
tapdiameter, pitchPitch used for spindle sync
thread_milldiameter, threadDirectionRequires thread milling pathing