Another way for such applications can be to use a local coordinate system for each part.

**Example**: Assume that the length of the part, including the part-off width, is 50 mm, and the length of the workpiece, sticking out of the chuck, is sufficiently more than 200 mm, so that four pieces could be machined out of it. The available machining program is suitable for machining just one piece, the front face of which is at Z = 0. Therefore, for machining second, third and fourth pieces, the origin of Z would need to be suitably shifted to the left, so as to have Z = 0 at the front face of every new piece. The required shift to the left would be 0 mm, 50 mm, 100 mm and 150 mm, for first, second, third and fourth pieces, respectively (The first piece requires no shift). A negative sign with the shift values would be needed because the positive direction of the Z axis is towards right.

#1 = 1; (Initializing macro variable #1 which is the part counter)

#2 = 4; (Variable #2 is the total number of parts)

#3 = 50; (Variable #3 is the length of part, including part-off length)

WHILE [#1 LE #2] DO 1; (Loop to be executed #2 times, i.e., once for each part)

G52 Z−[[#1 – 1] * #3]; (Local coordinate system defined, with Z = 0 at front face)

<Machining program, including parting operation>

#1 = #1 + 1; (Part counter incremented by 1)

END 1; (End of the loop. The execution exits the loop after all parts are machined)

G52 Z0; (Local offset cancelled, which reinstates the original WCS)

If this program is required to be used for a different number of parts and/or a different part length, then variables #2 and #3 would need to be accordingly assigned the new values, in the second and the third blocks, respectively. For example, if five parts, each of the total length of 40 mm, are to be machined, then these blocks would change to

#2 = 5;

#3 = 40;

Rest of the blocks would remain unchanged. This is the beauty of macro programming which allows one to write a general program, requiring very few changes for a different requirement.