Practical Examples

10. Custom Macro

Practical Examples

Practical Macro Examples

Collection of practical examples to better understand parametric programming.

1. Parametric Rectangular Pocket

O9001 (RECTANGULAR POCKET)
; G65 P9001 X.. Y.. Z.. W.. H.. D.. S.. F..
; X,Y = Pocket center
; Z = Total depth
; W = Width
; H = Height
; D = Tool diameter
; S = Z step
; F = Feed rate

#100 = #24 - #7               ; Usable width (W - D)
#101 = #11 - #7               ; Usable height (H - D)
#102 = 0                      ; Current depth

G0 X#24 Y#25 Z5

WHILE [#102 GT #26] DO1
  #102 = #102 - #19           ; Decrement by step
  IF [#102 LT #26] THEN #102 = #26

  G1 Z#102 F[#9/2]            ; Plunge

  ; Inner rectangle
  G1 X[#24 - #100/2] F#9
  G1 Y[#25 + #101/2]
  G1 X[#24 + #100/2]
  G1 Y[#25 - #101/2]
  G1 X[#24 - #100/2]
  G1 Y#25
  G1 X#24
END1

G0 Z5
M99

2. Grid Hole Pattern

O9003 (HOLE GRID)
; G65 P9003 X.. Y.. I.. J.. P.. Q.. Z.. R.. F..
; X,Y = Start point
; I = X spacing
; J = Y spacing
; P = Columns
; Q = Rows
; Z = Depth
; R = R plane
; F = Feed

#100 = 0                      ; Row counter
WHILE [#100 LT #17] DO1
  #101 = 0                    ; Column counter
  WHILE [#101 LT #16] DO2
    #102 = #24 + [#101 * #4]  ; Calculate X
    #103 = #25 + [#100 * #5]  ; Calculate Y

    G0 X#102 Y#103
    G81 Z#26 R#18 F#9         ; Drilling cycle
    G80

    #101 = #101 + 1
  END2
  #100 = #100 + 1
END1

M99

Tip: Always test macros at reduced speed before production use.