CNC Program Header and Safe Start Block Generator
Consistent program headers make NC programs easier to find, review and trust. A good safe start line cancels everything left over from the previous program, so the first move does what the programmer intended. This generator builds that header in a few seconds.
Fill in
Program header and first tool
% O4821 (BRKT-48213-A REV C) (OP10 FACE AND POCKET) (PROGRAMMER AJ, 2026-10-20) (T1 50 MM FACE MILL) (WORK OFFSET G54) G90 G17 G40 G49 G80 G94 G21 (SAFE START LINE) G91 G28 Z0 (RETURN Z TO HOME) G90 T1 M6 G54 G0 X0.0 Y0.0 S1800 M3 G43 H1 Z100.0 M8 (MACHINING BLOCKS GO HERE) G91 G28 Z0 M9 M5 G28 X0 Y0 M30 %
This is a generic Fanuc style starting point for a milling center. Metric units (G21) are assumed, so change to G20 for inch programs. Verify the coolant codes, return to home commands and tool change macro on your machine. Review every program in single block before first cut.
Link NC programs to routings
Optional: a conversation on tying program numbers and revisions to ERP routings and work orders.
Optional. The tool and every export work without this. No spam.
How to use the generator
Fill in the program number, part number, drawing revision, operation and the first tool. The code block updates immediately. Copy the result into your CAM post, editor or machine, or export it to include in a setup package. Adjust the home return and tool change blocks to match your machine builder's recommendations.
What the safe start line does
G90 selects absolute mode, G17 selects the XY plane, G40 cancels cutter compensation, G49 cancels tool length compensation, G80 cancels any canned cycle and G94 sets feed per minute. G21 selects metric units. Together they put the control in a known state regardless of what the last program or MDI command left active.
- G90 absolute positioning
- G40 and G49 cancel compensation
- G80 cancels canned cycles
- G94 feed per minute, G21 metric
Why the header comments matter
Part number and drawing revision in the first comment let an operator verify they loaded the right program for the job on the traveler. Many shops also record the programmer and date so a change can be traced. Keep comments short and uppercase, since some controls limit comment length or character sets.
Common mistakes
Leaving out G49 before a tool change on a machine with a leftover offset, starting without a Z home return, and putting a work offset call after the first rapid. Another mistake is changing the revision in the drawing but not in the program header, which defeats the point of the comment.
Frequently Asked Questions
What is a safe start line in G-code?
It is a block at the top of a program that cancels modal states such as cutter compensation, tool length compensation and canned cycles, and sets absolute mode and units. It prevents leftover settings from affecting the first moves.
Do I need G28 before a tool change?
It depends on the machine. Many mills require Z at its home position before M6, and some do this inside the tool change macro. Follow the machine builder's recommended tool change sequence for your model.
Should the header use G20 or G21?
Use G21 for metric and G20 for inch programs. Some shops avoid mixing by setting units in the post processor and a comment in the header, so operators never wonder which system the program uses.
Can I add more tools to this template?
Copy the generated tool call, spindle start and G43 lines for each additional tool and change the numbers. Many CAM systems do this automatically; the template is mainly for hand written programs and standard headers.
If drawing revisions, NC programs and traveler data live in different systems, we can discuss linking them so the right program is always tied to the right revision.
Related Tools
Fanuc Bolt Hole Circle Macro Generator
Fill in center, radius, number of holes and drill cycle values and get a ready to review Fanuc macro for a bolt hole pattern.
Discrete ManufacturingFanuc Macro B System Variables Reference
A lookup table of widely used Fanuc Custom Macro B variable numbers for offsets, positions, timers and alarms.
Engineering & PLMCNC Program Revision Log Worksheet
An editable log of CNC program changes with revision, reason, proveout status and approver, exportable to Excel.
MES & Shop FloorCNC Pre-Run Setup Verification Checklist
A checklist for the operator or setup technician to confirm program, tools, offsets, workholding and safety before running production.
More Developer Tools tools
See all- SAP Sales Order ABAP SELECT Generator (VBAK, VBAP, VBFA)
- SAP Sales Order Create BAPI ABAP Generator (BAPI_SALESORDER_CREATEFROMDAT2)
- SAP ABAP Open Items SELECT Generator
- SAP ACDOCA SQL Query Generator
- SAP QM Inspection Lot ABAP SELECT Generator
- SAP Quality Notification Pareto SQL Query Generator
- SAP QM Usage Decision BAPI Skeleton
- ABAP Custom Exception Class Generator
- ABAP Unit Test Class Generator