Macro variables, mathematical expressions, conditions and loops are useful when programming repeated features and parametric contours. They let a program calculate coordinates and change geometry through a set of input parameters.
Checking these algorithms solely on a machine is inconvenient. A program may contain hundreds of repetitions, calculated coordinates and nested conditions. An error in a loop increment or formula can affect many moves at once.
NCPlayer is an online CNC program simulator and editor from TRASA3. It runs in a browser, combining G-code editing, interpretation of supported macro constructs, toolpath visualisation and analysis tools. Separate profiles are available for FANUC, HAAS and SYNTEC programs.
From fixed coordinates to a parametric algorithm
In a conventional program, motion coordinates are specified in advance. When part dimensions change, the corresponding points need to be recalculated. A macro program calculates those points from formulas and input variables.
Parameters can include radius, hole or feature count, angular spacing, depth, feed rate, starting coordinates and pass count. This approach is useful for hole grids, circular patterns, slots, spirals and other parametric contours.
For example, a radius and feature count can be defined as follows:
#100 = 50.
#101 = 12.
#102 = 360. / #101
Here, #100 specifies a radius of 50 mm, #101 sets the feature count to 12, and #102 calculates an angular increment of 30 degrees. Changing 12 to 24 produces a 15-degree increment. The coordinate formulas stay the same.
FANUC, HAAS and SYNTEC profiles
The NCPlayer interface offers these options:
- FANUC 0i-MB: FANUC-style milling programs.
- FANUC Lathe: turning programs.
- HAAS VF-1: a HAAS milling machine profile.
- SYNTEC 6MB: a profile supporting the corresponding syntax and macro constructs.
- CUSTOM SIM: a custom simulation configuration.
The profiles account for differences in program interpretation. On real equipment, system variables, special M-codes and macro availability also depend on the controller version, machine parameters and installed options.
HAAS VF-1 and SYNTEC 6MB are marked as Premium in the interface. Some analysis and export tools carry the same label. Check feature availability when choosing how to work with a program.
FANUC Macro B: variables, calculations and conditions
Macro variables
For FANUC-style programs, NCPlayer provides local variables #1–#33, common program variables #100–#199 and a separate #500–#531 range. Supported system variables associated with the simulation state are also processed.
Local variables are used, among other purposes, to receive arguments passed to macro subprograms. With common variables, keep track of which program sections modify the same value. Storage in the simulator does not by itself establish how a variable behaves when a real controller is switched off.
Mathematical expressions
Expressions can contain arithmetic operations, brackets and nested calculations. Supported functions include:
- SIN, COS, TAN: trigonometric functions.
- ASIN, ACOS, ATAN: inverse trigonometric functions.
- ABS: absolute value.
- SQRT: square root.
- ROUND, FIX, FUP: rounding functions.
- MOD: remainder after division.
The following expressions calculate a point from a radius and angle, with #100 holding the radius and #101 the angle in degrees:
#102 = #100 * COS[#101]
#103 = #100 * SIN[#101]
The results give X and Y coordinates for a circle centred at the coordinate origin. Changing the angle generates successive points on that circle. Connecting those points with linear moves produces a polygonal contour.
IF conditional branches
A conditional branch selects the next step according to a comparison:
IF [#100 GT 50] GOTO 100
If #100 is greater than 50, execution jumps to block N100. Comparison operators are EQ for equal, NE for not equal, GT for greater than, GE for greater than or equal, LT for less than, and LE for less than or equal.
Conditions can select a sequence based on part diameter, repetition count or another parameter. Check both paths: what happens when the condition is true and how execution proceeds when it is false.
A WHILE loop: an instructional octagon
WHILE / DO / END loops repeat a section of the program. The following example creates a closed octagon in the XY plane at a constant Z20:
#100 = 0
#101 = 40
#102 = 45
G21 G17 G90
G00 X40. Y0. Z20.
WHILE [#100 LT 360] DO1
#100 = #100 + #102
#103 = #101 * COS[#100]
#104 = #101 * SIN[#100]
G01 X[#103] Y[#104] F300.
END1
M30
#100 holds the current angle, #101 sets the radius to 40 mm, and #102 defines a 45-degree increment. The starting point is X40 Y0. Each iteration increases the angle, calculates the next point and makes a linear move.
The loop runs eight times. Its final point corresponds to 360 degrees and closes the contour. The condition #100 LT 360 then becomes false.
This is an instructional geometry example for the simulator. Every move stays at Z20, and the program does not define a complete machining process. In NCPlayer, you can follow the construction of each side and examine how changing the increment affects the result.
HAAS and SYNTEC program features
HAAS VF-1
The HAAS VF-1 profile processes supported HAAS milling programs. Parametric algorithms can use numeric variables, expressions, mathematical functions, conditions, loops and subprograms.
Similarities with FANUC Macro B allow familiar techniques for calculating points and repeated features. For production, however, verify the program against the specific generation of HAAS control. Macro availability on the machine depends on its software options and configuration.
SYNTEC 6MB
SYNTEC has a separate profile because its structured constructs differ from FANUC-style syntax. Support includes:
- assignment using :=;
- IF / ELSE / END_IF conditions;
- WHILE / END_WHILE loops;
- FOR / END_FOR loops;
- expressions using macro variables.
Select the profile before checking the program so that the simulator interprets its control-flow constructs appropriately. Special system variables, PLC functions and machine-specific commands require separate compatibility checks.
A parametric toothed contour
A repeating toothed contour provides a clear example of macro programming. Input variables specify the starting coordinates, profile dimensions, tooth count, tooth depth and angular increment.
A loop calculates successive contour features, while SIN and COS convert radii and angles into X and Y coordinates. Variables store intermediate results. Changing the tooth count or size recalculates the points without editing each coordinate manually.
The visualisation window lets you examine the resulting toolpath relative to the coordinate system, tool and displayed stock. This helps check point order, contour closure and feature repetition.
The construction demonstrates a geometric algorithm. Manufacturing a gear also requires a calculated working tooth profile, tool and process selection, and checks of machine kinematics and machining conditions. A toothed outline alone does not establish that the profile is suitable for meshing.
Visualisation and variable monitoring
When coordinates are calculated in a loop, the source text alone may not make the result clear. NCPlayer displays the sequence of calculated movements in an interactive viewport.
- The 3D view supports changing the viewing direction and zoom to examine a spatial toolpath.
- The 2D view is useful for checking planar contours.
- Rapid and feed-move display helps distinguish positioning from moves at a specified feed rate.
- Playback speed, pause and resume allow closer examination of selected sections.
- Tool following helps track the tool position during playback.
The macro variable table
The variable table displays current values of supported variables during simulation. With #100 = #100 + 1, you can watch a counter change. The expression #101 = 40 * COS[#100] lets you compare the angle with the calculated coordinate.
This tool helps identify incorrect starting values, increments or exit conditions, as well as changes to a common variable inside a subprogram. Pause playback to inspect intermediate results when investigating a complex formula.
Explicitly initialise the variables used before repeating a check. This makes calculations reproducible and prevents an example from depending on values left over from a previous run.
Subprograms and preprocessed code
M98, M99 and G65
In supported FANUC-style syntax, M98 P1000 calls an ordinary subprogram. M99 returns from it.
G65 calls a macro subprogram with arguments:
G65 P9001 A40. B12.
This call invokes O9001 and passes two arguments. Under the standard FANUC Macro B argument assignment scheme, A maps to local variable #1 and B to #2.
The same algorithm can therefore be called with different parameters. A circular hole-pattern subprogram, for example, could receive a diameter and hole count. O9001 must be present and contain the required logic; the call itself does not create it.
View Preprocessed Code
A few lines inside WHILE can generate tens or hundreds of moves. To prepare the toolpath, the simulator evaluates expressions, processes conditions and expands supported loops and subprogram calls.
View Preprocessed Code displays the result. You can compare the original parametric algorithm with the calculated coordinates and generated command sequence.
This view helps check repetition counts and motion order. Use it alongside the variable table when examining current variable values. The preprocessed-code viewer is marked as Premium in the interface.
Toolpath analysis and export
NCPlayer provides tools for inspecting individual path sections, navigating from geometry to the corresponding program line and analysing motion coordinates. Depending on the mode, available information includes segment start and end coordinates, coordinate changes, checks against available limits and estimated program runtime.
An incorrect radius, for example, produces a contour of an unexpected size. A wrong coordinate sign can mirror a section, while an incorrect angular increment changes the placement of repeated features. Visualisation helps reveal these results before the program is transferred to equipment.
Runtime estimates depend on the calculation settings. They are useful for preliminary analysis; actual cycle time also depends on the behaviour of the real machine.
Further tools include saving and exporting CNC programs, exporting supported toolpaths to DXF, converting arc formats, and normalising and formatting G-code.
DXF is useful for comparing geometry with a CAD drawing. Exporting a toolpath does not automatically create a machining process. DXF export, Inspection mode, runtime calculation and several conversion tools are Premium features in the interface.
Learning and preliminary program checks
NCPlayer helps operators understand motion sequences and learn macros through instructional examples. Programmers and setup personnel can examine coordinate calculations, loops and parametric subprograms.
Instructors can show the source algorithm, changing values and toolpath together. Students can change a radius or repetition count and observe the effect on geometry.
Simulation covers supported commands and functions. It does not fully reproduce the machine, its PLC, safety devices, tooling and every controller-specific behaviour. A toolpath preview cannot guarantee collision avoidance or replace process verification.
Before production, check compatibility with the actual controller, offsets and tooling, workholding and the safe execution sequence. Pay particular attention to system variables, special M-codes and functions dependent on machine options.
NCPlayer brings together editing, macro interpretation and visual motion analysis. Variables, conditions, loops and subprograms can be studied within one example by comparing input parameters with the calculated toolpath.
Launch NCPlayer · English documentation · Supported codes and parser capabilities.