Script Commands
What Is a Script Command?
A script command is a C# statement executed by the HiNC scripting engine. Scripts directly reference members and methods of SessionShell, which serves as the global scope — no explicit object reference is needed.
// These are all SessionShell members used directly as globals
EnablePhysics = true;
MachiningResolution_mm = 0.125;
PlayNcFile("NC/file1.nc");
Message("Done");
Script Syntax Basics
Scripts use native C# syntax:
| Feature | Syntax |
|---|---|
| Statement terminator | ; |
| End-of-line comment | // comment |
| String interpolation | $"Value is {variable}" |
| Positive infinity | double.PositiveInfinity |
| Negative infinity | double.NegativeInfinity |
| Bitwise OR (for flags) | Fx|Fy|Fz |
All standard C# language features (variables, loops, conditionals, LINQ, etc.) are available.
Execution Model
Session Lifecycle
- Scripts execute in order on the Task page
- A PacePlayer(API) controls playback — script commands like PlayNcFile(API) block until the NC program completes
- Player control commands (Pace()(API), Pause()(API), Reset()(API)) interact with the PacePlayer(API)
- ResetRuntime(API) clears event handlers, buffers, and runtime state
Event-Driven Execution
Events like SessionStepBuilt(API) fire during simulation and allow per-step logic:
SessionStepBuilt += (preStep, curStep) => {
if (curStep != null)
Message($"Step: ToolId={curStep.ToolId}");
};
PlayNcFile("NC/file1.nc");
Events are cleared by ResetRuntime.
Script Commands in NC Code
Script commands can be embedded inside NC code comments. Lines starting with ;@ execute before that NC line runs:
The marker is read inside the line's comment, so the comment character is the controller's own. Where ; opens a comment:
T01 M06 ;@MachiningResolution_mm=0.03125;
S1270 M03
G43 Z10. H01
For controllers that do not support ; as a comment character (FANUC and the other ( ) dialects), the same marker goes inside the parentheses:
T01 M06 (;@MachiningResolution_mm=0.03125;)
S1270 M03
G43 Z10. H01
File Path Templates
Commands that output files support the [NcName] token, which is replaced with each NC file name:
PlayNcFile("NC/file1.nc");
PlayNcFile("NC/file2.nc");
WriteShotFiles("Output/[NcName].shot.csv", 1);
// Produces: Output/file1.nc.shot.csv, Output/file2.nc.shot.csv
All file paths are relative to the project directory unless an absolute path is given.
Important Warnings
The following operations can corrupt simulation state or produce incorrect results:
- Do not save the project during simulation. System-internal configuration (e.g., training-specific resolution overrides) may overwrite your settings.
- Do not reset the player during milling coefficient training. Close the project instead of pressing the reset button to avoid unexpected errors.
- Do not modify resolution, tool, or controller settings during training. Changing these mid-training invalidates the results.
- Do not combine
UpdateNcOptOptionin SessionStepBuilt(API) with NC-embedded optimization commands. Parallel computation may cause undefined behavior. - Do not write
NaNinto a per-stepNcOptOption. ANaNfeed-per-tooth boundary is refused when the step is solved: that step keeps its simulated feed rate and is reported as an error naming the option values, and the rest of the run is optimized normally. See When a Step Cannot Be Solved.
Global Variables
Global provides a key-value dictionary for sharing data across scripts:
Global["material"] = "Steel";
var material = Global["material"];
Full API Reference
For the complete list of available commands, properties, and events, see:
- SessionShell — full API documentation
- SessionShell — the command families, and which workflow uses each
See Also
- SessionShell — the command families this syntax reaches
- Step — machining step data model
- Workflow: Basic Machining Simulation — using scripts in a simulation workflow
- Cutter-Location (CL) Playback — replaying a CL toolpath from a script
- ShellProgress — the message stream a running script writes to
- NC Optimization — what a per-step optimization option does, and how a step that fails to solve is reported