Skip to content
Back
Tooling & Machines

How do I get the job name, tool, material size and date written as comments at the top of my G-code file?

Updated Oct 13, 20263 min readVCarve Pro & Aspire

How comments get into the file

Comments in the output are just quoted lines in the post processor's HEADER (or TOOLCHANGE and NEW_SEGMENT) that the controller is told to ignore. The post fills them in with variables. Many G-code controllers treat text inside parentheses as a comment. LinuxCNC also accepts a semicolon for the rest of a line. Check which style your controller uses.

Useful lines to add

In a custom copy of your post, add lines like these inside begin HEADER, above the first real G-code line:

"( [TP_FILENAME] )"
"( File created: [DATE] - [TIME] )"
"( Material X= [XLENGTH], Y= [YLENGTH], Z= [ZLENGTH] )"
"( Z zero: [Z_ORIGIN]  XY origin: [XY_ORIGIN] )"
"( Safe Z = [SAFEZ] )"
"( Toolpaths: [TOOLPATHS_OUTPUT] )"
"( Tools: [TOOLS_USED] )"

Other variables worth knowing: [TOOLNAME] and [TOOLPATH_NAME] for the current tool and toolpath, [FILE_NOTES] for the text typed under Edit, Notes, [TOOLPATH_NOTES] for notes on a toolpath, and [PRODUCT] for the program name and version.

The Z zero and XY origin lines are the most valuable. They tell whoever runs the file where to zero the machine.

When the comment itself causes an error

Tool names in the Tool Database often contain parentheses, for example a size in brackets after the name. Put that inside a parenthesis comment and you get a comment within a comment. The Mach3 manual states that comments may not be nested and treats it as an error.

The fix is the SUBSTITUTE statement near the top of the post. It swaps characters inside variable text, written as pairs: original, then replacement. The line SUBSTITUTE = "({)}" turns ( into { and ) into }, so the tool name no longer breaks the comment. The shipped Mach posts use exactly this.

Special characters

Square brackets and the double quote have special meaning in a post and cannot be typed as plain output. Use their codes in square brackets instead:

  • [91] outputs a left square bracket
  • [93] outputs a right square bracket
  • [34] outputs a double quote

To remove comments

Delete the comment lines from the block, or pick a post without them. Small controllers with limited memory or short line limits sometimes need this.

Pro tips

  • Keep each comment line short. Grbl, for example, rejects a line that exceeds its character limit (error 11).
  • A (Tool: [TOOLNAME]) line in TOOLCHANGE makes many controllers show which bit to load next.
  • See the entry on what the bracketed variables mean for the full list.

Sources and further reading

15. Advancedthe software maker's documentation (opens in a new tab)Mach3Mill 1.84machsupport.com (opens in a new tab)G-code Overviewlinuxcnc.org (opens in a new tab)Grbl v1.1 Interface · gnea/grbl Wiki · GitHubgithub.com (opens in a new tab)
Did this help?

Still stuck? Ask the community

Ask in your own words. Vector answers first, from the guides. If that does not cover it, post it to members and the shop from there.

Ask your question