Skip to content

Preprocessors

Marius Stanciu edited this page Oct 29, 2026 · 1 revision

A preprocessor turns the job into G-code (or another machine language) for one machine. Choose it in the Preprocessor combo box of the tool. Use the one that matches your controller.

Where to find it

  • The Preprocessor combo box of each tool: Milling, Isolation, Drilling, NCC, Paint, Cutout, and the other tools that make a CNC job.
  • The default for each tool is set in its preferences (see Preferences Plugins).
  • The Export G-Code button of a CNC Job object uses the preprocessor of the job. A Roland job saves .rol, a NCCAD9 job saves .knc, and an HPGL job saves .plt.

Quick start

  1. Find your controller in the table in section Advanced. If it is not in the table, use default (MACH3 compatible) or GRBL_11 (GRBL firmware).
  2. Open the tool (for example Milling) and select the Preprocessor in its Preprocessor combo box.
  3. Make the job. The CNC Job object shows the G-code in its text box.
  4. Check the start and end code in the G-code editor before you send the file to the machine.
  5. Click Export G-Code and save the file.

Parameters

The preprocessor has no parameters of its own. The job values (feedrates, Z heights, spindle speed) come from the tool. The preprocessor uses the decimals of the job, set in the G-code Decimals group of Preferences CNCJob.

Advanced

Table of the preprocessors

The table lists each preprocessor file in the preprocessors folder. The name in the table is the class name (the combo box shows the same name).

Preprocessor Target machine or use Specific behavior
default MACH3 compatible controllers The header writes the job data as comments. The tool change uses M5, Z up, T, M6, a message, and M0 (pause). Feed commands use G01 F. The spindle uses M03 or M04 with S, and M05 to stop.
default_laser MACH3 laser (laser on or off by M3, M4, M5) Rapid moves are G00 and cut moves are G01. The laser on command comes from the tool (laser_on_code).
Default_no_M6 MACH3 without a tool changer (no M6) As default, but the tool change does not use M6. It uses the M0 pause only.
GRBL_11 GRBL 1.1 firmware Header with G17, G21 or G20, G90, G94. Spindle with M03, M04, M05. Tool change with M5, Z up, M6, and M0.
GRBL_11_no_M6 GRBL 1.1 without a tool changer As GRBL_11, but the tool change does not use M6. It uses the M0 pause only.
GRBL_laser GRBL laser Laser on with M3 or M4, off with M5. Cut moves are G1 with the feedrate. No Z moves.
GRBL_laser_z GRBL laser with a Z axis As GRBL_laser, with Z moves (G0 Z, G1 Z) in the job.
grbl_laser_eleks_drd GRBL laser without a Z axis, for etching small holes Written for lasers without Z. Drill holes of an Excellon job are made as G02 arcs (small and bigger circles). The GRBL controller must support G2.
Marlin Marlin firmware Marlin has no M6 and T selects an extruder. The tool change uses G0 Z, moves to the tool change point, and pauses with M0 and a message. Dwell with G4 P (ms) or G4 S (seconds). Spindle with M3, M4, M5.
Marlin_laser_z Marlin laser with Z moves Laser on with M3 S (power from the laser minimum power) and off with M400 then M5. Feedrates are inline with the moves.
Marlin_laser_FAN_pin Marlin laser with the laser on the fan output The laser is on and off with M106 S. Off is M106 S0.
Marlin_laser_Spindle_pin Marlin laser with the laser on the spindle output The laser is on and off with M3, M4 and M5. Off is M400 then M5.
Repetier Repetier firmware Fan output used for the laser or spindle state (M106, M107). Tool change with M400, M107, G0 Z and G0 X Y.
Berta_CNC Berta CNC machine Start code is specific to the controller: G90 G17 G91.1, G64 P0.03, M110. Tool change with M5, G00 Z, M6 and M0. Ends with M30.
Check_points A probe check at the cut depth At the cut depth the tool stops with M0 for the operator to check the point. The stop is an M0 pause for the check.
Line_xyz A machine that moves X, Y and Z together on the tool change The tool change moves X, Y and Z in one G00 line, then M6 and M0.
Toolchange_Manual Manual tool change The tool change stops with M0 on each change (no automatic tool changer). The program waits for the operator.
Toolchange_Probe_MACH3 MACH3 with a touch probe for tool length The tool change uses the probe: G31 Z moves until the probe touches, and G92 Z sets the Z zero from the touch plate thickness.
ISEL_CNC ISEL CNC controller Header uses G70 or G71 (inch or mm). Pauses use M00 (a mandatory stop). M01 is not used for pauses. Dwell with G4 P.
ISEL_ICP_CNC ISEL ICP controller (own language) Coordinates are whole micrometres (the ICP language). Feedrates are micrometres per second. The start point is a workpiece zero (WPCLEAR clears it). No header comment.
NCCAD9 NCCAD9 (KOSY) machine Output is the KOSY format (file .knc). Tool change uses M10 O6.0 (spindle stop), G76 (reference point), and G77 (release position). Pauses use M01.
Roland_MDX_20 Roland MDX-20 mill (RML-1 language) Output is RML-1 (file .rol). Units are 0.025 mm (40 units per mm). Feedrate range 6 to 900 mm/min. The plunge uses the Z feedrate. RML-1 has no operator pause.
Roland_MDX_540 Roland MDX-540 mill (RML-1 language) Output is RML-1 (file .rol). Units are 0.01 mm (100 units per mm). Feedrate range 6 to 7500 mm/min.
hpgl HP-GL plotter (not a Roland mill) Output is HP-GL (file .plt). Coordinates are integers in plotter units of 0.025 mm (40 units per mm), clamped to -32768 to 32767. Metric only: inch jobs are converted. Pen up and down are the Z moves.
Paste_1 Solder paste dispenser (generic) Used by the Solder Paste tool only. Dispenser moves (G01), the dispense Z (z dispense, z stop), the dispense spindle (M03 S and M04 S). Tool change moves at the travel Z.
Paste_GRBL Solder paste dispenser on GRBL As Paste_1, for a GRBL controller. Uses GRBL-style G01 moves.
Paste_Marlin Solder paste dispenser on Marlin As Paste_1, for a Marlin controller. Uses G1 moves and M3 S for the dispense. Tool change pauses with M0.

The Paste_ preprocessors use the solder paste method set (AppPreProcTools), not the milling one.

How to choose

  • Use the name of your controller or firmware: GRBL, Marlin, Repetier, MACH3, ISEL, Roland.
  • For a laser, use a laser preprocessor. Check which pin starts the laser: spindle pin (M3, M4, M5) or fan pin (M106, M107).
  • For a Roland or HP-GL machine, the file type is not G-code (see the table). The export button saves the matching file type.
  • For a solder paste dispenser, use one of the Paste_ preprocessors in the Solder Paste tool.
  • If the name of the preprocessor of a loaded project is not installed, the job uses default.

Write a custom preprocessor

  1. Copy a file that is close to your machine (for example GRBL_11.py) to your own folder: preprocessors in the data folder (see Preferences Overview for the data folder).
  2. Rename the file and the class to a name you choose. The name must be unique: a second class with the same name replaces the first one. The export button picks the file type from the preprocessor name: a name that contains Roland (case sensitive) saves .rol. A name that contains nccad (any case) saves .knc. A geometry preprocessor name that contains hpgl saves .plt.
  3. Edit the methods listed below.
  4. Restart FlatCAM Evo. The new name appears in the Preprocessor combo box.

Each preprocessor is a class that inherits PreProc from appPreProcessor.py. The class is registered when the file is loaded. A file that cannot be loaded is reported in the log, and the others are still loaded.

Methods you must write

Each of these methods returns G-code text. The argument p holds the job values (see the variable list).

Method Called for
start_code(p) The header and the start of the job (units G20 or G21, G90, spindle speed, comments).
lift_code(p) Move the tool up to the Travel Z (z_move).
down_code(p) Move the tool down to the cut depth (z_cut).
toolchange_code(p) The tool change: stop, move to the change point, change tool, pause.
up_to_zero_code(p) Move up to the top of the material (Z 0), before the Travel Z.
rapid_code(p) A fast XY move (G00 or G0).
linear_code(p) A cut XY move (G01 or G1).
end_code(p) The end of the job: Z up, then the XY end position.
feedrate_code(p) Set the XY feedrate.
spindle_code(p) Start the spindle in the direction spindledir with the speed spindlespeed.
spindle_stop_code(p) Stop the spindle.

Methods you may change

The base class (PreProc) has default versions of these methods. Change them only when your machine needs a different form:

Method Default
startz_code(p) G00 Z at the Start Z (startz), or nothing.
z_feedrate_code(p) G01 F with the Z feedrate.
dwell_code(p) G4 P with the dwell time in seconds, or nothing.
position_code(p) X and Y text of the bed-corrected position.
coord(p, value) A coordinate with the job decimals.
bed_xy(p, x, y) The machine position: bed offset added and bed skew applied.
end_xy_move_z(p) The Z of the final XY move (the higher of End Z and Travel Z).
end_moves_code(p, rapid, z_rapid, suffix) The end moves: Z, then XY, then Z to the End Z if it is lower.

Also set these class attributes:

Attribute Meaning
coordinate_format The Python format of a coordinate, for example "%.*f" (decimals taken from the job). Roland files use "%d".
feedrate_format The Python format of a feedrate, for example '%.*f'.
feedrate_rapid_format The format of the rapid feedrate (optional, default is feedrate_format).
include_header True writes the job header. The ISEL ICP and Roland files use False.

Variables available in p

These are the values the job gives to the preprocessor. Use them as p.name or p['name'].

Variable Meaning
p.x, p.y The position of the current move.
p.z_move Travel Z (the safe height).
p.z_cut Cut Z (the depth of the cut).
p.z_end, p.xy_end End Z and the End XY position (or None).
p.startz Start Z (or None).
p.z_toolchange, p.xy_toolchange Tool change Z and XY (or None).
p.feedrate, p.feedrate_rapid XY cut and rapid feedrate.
p.z_feedrate Z feedrate.
p.spindlespeed, p.spindledir Spindle speed and direction (CW or CCW).
p.dwelltime Dwell time in seconds.
p.tool, p.toolC The tool number and the tool diameter.
p.is_first_tool True for the first tool of the job.
p.toolchange True when the tool change is on.
p.f_plunge True when the plunge is a fast move (G00).
p.units MM or IN.
p.coords_decimals, p.fr_decimals, p.decimals Decimals of coordinates, feedrates, and other values.
p.multidepth, p.z_depthpercut Multi-depth on or off, and the depth per pass.
p.steps_per_circle Segments per circle.
p.pp_geometry_name, p.pp_excellon_name The names of the preprocessors.
p.obj_options The object options (name, type, xmin, xmax, ymin, ymax, tool diameter).
p.tools The tools of the Excellon job (drills, tool diameters, feedrates).
p.use_ui True when the job comes from the user interface.
p.laser_on_code, p.laser_min_power Laser on command and minimum laser power (laser tools).
p.z_p_depth, p.feedrate_probe, p.probe_plate Probe depth, probe feedrate, and the thickness of the probe plate.
p._bed_offset_x, p._bed_offset_y, p._bed_skew_x, p._bed_skew_y, p._bed_limit_x, p._bed_limit_y Bed offset, skew, and bed size (set in Preferences CNCJob).

Where to put it

  • Your own preprocessors: the preprocessors folder in the data folder. The files there are loaded first.
  • Built-in preprocessors: the preprocessors folder of the application. A file with the same class name in the data folder replaces the built-in one.

Test a preprocessor

Load a small job, export the G-code and check the output. Start with a simple Geometry job (one tool, one path). Then test the tool change and the end code.

See also

Clone this wiki locally