Variables

10. Custom Macro

Variables

Macro Variables

Variables are fundamental elements of parametric programming and allow storing and manipulating numerical values.

Variable Types

Range Type Description
#1 - #33LocalArguments passed to macro (A=#1, B=#2, C=#3...)
#100 - #199CommonShared between programs, cleared on power off
#500 - #999PermanentRetained even after power off
#1000+SystemAxis positions, machine states, timers

Common System Variables

Variable Description
#5001-#5006Block end position (X,Y,Z,A,B,C)
#5021-#5026Current machine position
#5041-#5046Current work position
#3001Millisecond timer
#3002Hour timer
#4001-#4021Active modal G codes

Using Variables

; Assignment
#1 = 25.5          ; Direct value assignment
#2 = #1 * 2        ; Operation result assignment
#3 = [#1 + #2] / 2 ; Complex expression

; Use in movements
G1 X#1 Y#2 Z#3 F500

; Use in parameters
G81 X0 Y0 Z[-#4] R2 F#5

; Indirect variables
#[#10] = 100       ; #10 contains variable number
#11 = #[#10]       ; Reads variable indicated by #10

Empty Variable (#0)

Variable #0 is always empty and can be used to:

  • Check if an argument was passed
  • Skip optional parameters
IF [#1 EQ #0] THEN #1 = 10  ; If #1 empty, use default 10

Note: Variable ranges may vary between controllers. Always check your specific controller manual.