ShopMill Program Template Auto-Generate Header and Footer NC Code

David Krause11 min read
Other TopicSiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Overview

Every ShopMill part program typically starts with a tool-clearance move and ends with a spindle stop, coolant off, table re-home, and rewind-to-start sequence. Typing those lines by hand on every new workpiece is wasteful, error-prone, and inconsistent across operators. The standard fix is a program template: a pre-filled MPF file that contains the agreed header/footer NC code, the work-area clearance moves, and the operator message block. New part files are then created by copying that template rather than starting from an empty file.

How the template is implemented depends on the ShopMill front-end in use. Siemens currently ships three HMI variants for the 810D/840D platform:

  • HMI Embedded – typical on 810D Powerline with PCU20 (the case in the source scenario).
  • HMI Advanced – PCU50 / PCU70 on 840D Powerline.
  • Sinumerik Operate (HMI sl) – PCU50.3 / NCU 7x0.3 and later on 840D sl.

All three can host a template, but the menu path and the file-naming rules differ. The procedure below covers each variant and also documents the related tool-change macro (L6.SPF) technique, which moves the same clearance logic into the tool change itself so that any part program benefits automatically.

Prerequisites

  • ShopMill license active on the controller (option bit / CF card slot enabled).
  • Operator password level that allows program editing and file management in the NC file system (default: manufacturer or service).
  • Access to the active NC file directory (MPF, SPF, CMA, WKS) on the CF card or NCU file system.
  • Knowledge of the active work offset, the fixed machine positions referenced by G75, and the spindle-clearance Z used on the machine.

Reference: The G-Code and M-Code Lines Involved

The header/footer block cited in the field report is built from the following Siemens (DIN 66025) codes. Reference them when building or auditing the template.

Code Group Function Used For
G75 Z0. G group 6 (special motion) Fixed-point approach in Z, position 0 Header: lift spindle off the part before tool change
G75 X0. Y0. G group 6 Fixed-point approach in X/Y, position 0 Header: clear the table before tool change
G500 G group 8 (work offset) Deselect all settable work offsets (G54–G599) Footer: return to base machine coordinate system
G00 X320. G group 1 (motion) Rapid linear interpolation Footer: park table at the loading-door X position
M5 M misc Spindle stop Footer: halt spindle rotation
M9 M misc Coolant off (all circuits) Footer: shut off flood + MQL
M30 M misc Program end with rewind to first block Footer: close program, reset pointer
MSG(" … ") High-level Display operator message in HMI Footer: confirm end-of-program to operator
M1 M misc Optional stop (active only when OP stop is enabled) Tool-change macro: pause for proving
Note on G75. G75 is modal only for the call (Siemens implementation: non-modal, executed once per block). It moves the addressed axes to a machine-defined fixed point; the coordinate after G75 names the fixed point, not the destination. Some 810D/840D Powerline cycles call this the tool-change fixed point. If the template's G75 Z0 does not move the spindle where expected, verify the machine data: MD20150 $MC_GCODE_DEFAULT_VALUES[75] and the fixed-point positions in MD30600, MD30610, ….

Method 1 – Template Workpiece (HMI Embedded / Operate)

Siemens documents a template workpiece feature for the standard HMI: a user-defined NC file that the system uses as the starting content for any newly created program. The official reference is the HMI Embedded / Operate programming manual, entry Siemens Support Entry 55622848 (chapter 6.7.12 in the embedded manual). Behavior is identical between ShopMill and ShopTurn under that entry.

Step-by-Step (HMI Embedded, PCU20)

  1. On the ShopMill start screen, navigate Program Manager > Templates. If the directory does not exist, create it under /_N_TEMPLATES_DIR from the services area.
  2. Create a new program file named, for example, _TPL_MPF in the templates directory. Use the underscore-leading naming convention reserved for system templates so the HMI does not display it in the main program list.
  3. Edit the file and paste the header/footer skeleton. Mark the editable region with a ShopMill program-section comment so the operator can locate the part-specific blocks:
    ;SHOPMILL TEMPLATE v1.0 - DO NOT EDIT HEADER/FOOTER
    G75 Z0.
    G75 X0. Y0.
    ;*** PROGRAM CONTENTS BELOW ***
    
    
    ;*** END PROGRAM CONTENTS ***
    M5
    M9
    G75 Z0.
    G75 Y0.
    G500 G00 X320.
    MSG(" *** END PROGRAM *** ")
    M30
  4. Save, then exit edit mode.
  5. From the user area, choose New > Part Program. The HMI will pre-fill the new file with the template body if the controller is configured to do so (see verification step below).
HMI Advanced caveat. On PCU50 with HMI Advanced, the menu path is Start-up > HMI > Template and the template is bound per channel rather than per directory. Set the channel-specific file in menudir.ini or via the start-up menu. The above template file name still applies, but the assignment is done in Commissioning > Channel.

Method 2 – Manual Copy of a Master Program

If the HMI variant does not support template workpieces, or the controller has been locked down to operator level only, the standard shop-floor workaround is to keep a master program in the work directory and copy it for every new part. This works on every ShopMill version, including legacy HMI Embedded PCU20 on 810D Powerline.

  1. Create the master file once: MASTER.MPF containing the header/footer shown above.
  2. Mark the file as read-only using the file-system attributes from the services area (SEDIT > file attributes) so operators cannot accidentally edit the master.
  3. Train operators to right-click the master, select Copy, and rename the copy to the part number. The ShopMill editor opens the new file with all of the standard lines already in place.
  4. Optionally, set the Program Manager default directory so that MASTER.MPF is always visible in the root of the work area.

This method has the advantage of working on any firmware version and is the fallback when Method 1 is not available. The disadvantage is that operators must remember to copy from the master; a single distracted keystroke creates a blank file and the safety envelope is lost.

Method 3 – Move the Logic into the Tool-Change Macro (L6.SPF)

The field report's author solved the same problem differently: by modifying the tool-change program L6.SPF so that the clearance moves happen before every T-call. This puts the safety envelope in one place that every program (new, legacy, or imported) inherits automatically, and it removes the dependency on operator discipline.

Recommended L6.SPF Skeleton

;L6.SPF - TOOL CHANGE MACRO (rev. 2)
;Moves spindle to clearance Z, sends table to machine zero,
;performs tool change, then resumes the calling program.

G75 Z0.                 ; lift spindle to fixed clearance point
G75 X0. Y0.             ; table to machine zero (clears workpiece)
M1                      ; optional stop - active only with OP stop
T=__                    ; tool change call (parameter from caller)
M1                      ; second optional stop for prove-out
RET

Behavior Notes

  • The first M1 pauses after the clearance moves; the second pauses after the tool is in the spindle. With the HMI's Program control / Single block or OP stop on, the operator gets two deliberate confirmations - useful when proving long-cycle programs or when coolant hoses need to be repositioned between tools.
  • Add a T0 pre-call at the very start of the part program to clear the spindle before the first useful cut, and a T0 at the end of the part program so the macro runs one final time after the last tool finishes. This delivers the same header/footer behavior without the operator typing it.
  • Because L6.SPF executes from the NC kernel, it does not need the part program to be a template. Even hand-edited MPFs or programs imported from CAM inherit the safety envelope.
Conflict warning. Some ShopMill cycles call L6.SPF implicitly via the tool-change block generated by the Tool step. If you rewrite L6.SPF, audit the cycle's generated NC for redundant or duplicate G75 calls; duplicate fixed-point approaches are harmless but waste cycle time and can confuse the operator's HMI trace.

HMI Variant Comparison

Feature HMI Embedded (PCU20) HMI Advanced (PCU50/PCU70) Sinumerik Operate (HMI sl)
Template workpiece in NC file system Supported per channel configuration Supported per channel configuration Supported, plus per-template settable frames
Menu path to assign template Start-up > HMI > Template Start-up > HMI > Template (channel tab) Start-up > HMI > Templates (operator surface)
Recommended location /_N_TEMPLATES_DIR /_N_CMA_DIR/_TPL /_N_TEMPLATES_DIR
L6.SPF macro editing Service level only Service level only Manufacturer / service level
Minimum ShopMill version 06.04 (typical for 810D PL) 06.04 / 07.01 04.50 + SPxx (HMI sl)

Verification

After installing a template - by any of the three methods - run the following checks before releasing the change to production:

  1. New-program test. Create a brand new MPF from the user area. Confirm the header lines (G75 Z0 / G75 X0 Y0) are present and the footer (M5, M9, G500 G00 X320., MSG, M30) is present, in that order.
  2. Block search. Use the HMI's Block search with calculation to start the program at the last block before M30. Confirm the controller computes a valid approach to the MSG(" *** END PROGRAM *** ") block and stops cleanly. A calculation error here usually means the work offset is still active and G500 is missing from the footer.
  3. Tool-change prove-out. With Dry run and OP stop enabled, run a two-tool program. Confirm the spindle lifts to clearance Z and the table moves to machine zero before each tool change. This verifies the L6.SPF modifications if Method 3 is used.
  4. MSG line test. Cycle the program; verify the HMI message bar shows *** END PROGRAM *** at the end and the channel rewind indicator returns to block 1.
  5. Backup. Archive the template file (_TPL_MPF or MASTER.MPF) and the modified L6.SPF to a versioned backup before sign-off. Both files live in CF card paths that are erased on a series start-up if not backed up.

Troubleshooting Matrix

Symptom Likely Cause Fix
New program created blank; template content missing Template file not assigned to active channel, or template lives outside the configured template directory Verify the template path in start-up; ensure the file has the _TPL_ naming convention and read permission
G75 Z0 does not move the spindle MD20150 default for G75 is not set, or fixed-point position 0 in Z is undefined Set MD20150[75] to a valid fixed-point ID; define the position in MD30600 and follow-up MDs
Spindle rotates past M5 because coolant is still on M9 placed after M30 (unreachable) or missing in footer Reorder to M5, M9, G500 G00, MSG, M30
Table parks at wrong X position after M30 Loading-door X coordinate changed after template was written Update the X value in the master template and re-issue to all copies, or use a settable work offset for the door position
L6.SPF modifications have no effect ShopMill cycle is calling a different tool-change subroutine (e.g., L6 is shadowed by a cycle-internal macro) Check MD10717 $MN_M_NO_FCT_EOP and the cycle's RESET path; confirm the active tool-change macro by adding a trace MSG("L6 ENTRY") on the first line
Operator sees "END PROGRAM" message and machine does not rewind Program ends with M2 instead of M30 Standardize the footer to M30; document in operator quick-reference card
Template visible in the user program list File name does not match the system template prefix Rename to _TPL_… or use a leading dot on file systems that support it

Best-Practice Notes

  • Single source of truth. Choose one of the three methods per machine. Mixing a template file with an L6.SPF rewrite creates two places to maintain and the two can drift when a ShopMill update changes the tool-change cycle.
  • Document the footer. Print the footer sequence on a laminated card next to the operator panel. M5 / M9 / G500 / G00 / MSG / M30 is the conventional order; deviating from it confuses service engineers who later audit the NC code.
  • Guard the work offset. Always re-issue G500 (or the canonical G54+) at the start and end of a program. A forgotten G500 after a subprogram that left G54 active is the single most common cause of first-cut crashes on a re-run part.
  • Use MSG, not comment lines, for operator messages. A leading-semicolon comment is invisible in the HMI status line; the MSG(" … ") command is shown until cleared with MSG("") or until a new MSG is issued.
  • Back up the template before every ShopMill upgrade. The upgrade procedure in Siemens Support 55622848 may reset the template directory if the install is performed at manufacturer level.

FAQ

Does every ShopMill version support a template workpiece?

No. The template-workpiece feature documented in Siemens Support Entry 55622848 is available on HMI Embedded and Sinumerik Operate. HMI Advanced supports a per-channel template file but the assignment is made in the start-up area, not the operator surface. If neither path is available, fall back to copying a read-only master program.

Where should the template file be stored on a PCU20 (810D Powerline)?

Use the system template directory /_N_TEMPLATES_DIR on the active NC file system, with a name prefixed by _TPL_ (for example, _TPL_MPF). The underscore-leading convention keeps the file out of the operator program list and reserves it for the template mechanism.

Is it safe to modify L6.SPF to add clearance moves and M1 stops?

Yes, provided the change is made at service or manufacturer access level, archived to a versioned backup, and tested with dry-run plus OP stop on a two-tool program. The M1 stops remain inactive during normal production unless the operator enables OP stop or single-block, so they impose no cycle-time penalty in production runs.

What is the correct footer line order for a ShopMill program?

The conventional order is M5 (spindle stop), M9 (coolant off), G75 Z0. (lift spindle), G75 Y0. (clear table in Y), G500 G00 X<door>. (deselect offsets, park table at loading door), MSG(" *** END PROGRAM *** ") (operator message), and finally M30 (program end with rewind). Reordering M9 after M30 or placing M30 before the G500 reset will produce a confused end-of-program state.

Why does G75 Z0 sometimes appear to do nothing?

G75 is a fixed-point approach in Siemens DIN 66025: the coordinate after G75 names the machine-defined fixed point, not a destination. If MD20150 $MC_GCODE_DEFAULT_VALUES[75] is empty or the Z fixed point (typically MD30600 and the related fixed-point table) is not defined for the active channel, the block runs as a no-op. Verify the machine data before assuming the template is wrong.

Back to blog