Glossary: 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 RuntimeApi, which serves as the global scope — no explicit object reference is needed.
// These are all RuntimeApi 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.
Script Task Page
In the HiNC GUI, the Task page contains one or more script panels. Each panel has:
- Order: Execution order (left to right, top to bottom)
- Enabled: Whether the script runs (unchecked = skipped)
- Title: A label for human reference only — has no functional effect
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:
T01 M06 (;@MachiningResolution_mm=0.03125;)
S1270 M03
G43 Z10. H01
For controllers that do not support ; as a comment character (e.g., FANUC), wrap in a comment block:
T01 M06 (;@MachiningResolution_mm=0.03125;)
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.
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:
- RuntimeApi — full API documentation
- Glossary: RuntimeApi Quick-Reference — categorized quick-reference table
See Also
- Glossary: RuntimeApi Quick-Reference — RuntimeApi quick-reference
- Glossary: Machining Step — machining step data model
- Workflow: Basic Machining Simulation — using scripts in a simulation workflow