spinner
{{ menu }}

SETVN (Set Variable Name) in FANUC Macro Programming

Large programs often rely on many common variables. When those variables are referenced only by numbers, the program can quickly become difficult to read and maintain. SETVN (Set Variable Name) is a feature that allows programmers to assign names to common variables, improving clarity and making macros easier to work with.

What SETVN Does?

It assigns aliases to common variables beginning with the variable number defined in the SETVN command. Instead of referencing variables by number (for example #500 or #501), you can assign meaningful names such as:
#RADIUS #ANGLE
These names act as direct aliases to the original common variables.

Variable Naming Rules

SETVN variable names The variable name (excluding #) can be up to eight characters long. Their can also include underscores, which can be useful when organizing parameters.
Examples:
#RADIUS_2 #ANGLE_2
This makes it easier to manage multiple related variables within larger macro programs.

Control Compatibility

SETVN is not supported on all FANUC controls, especially older models. It is typically available on newer generations such as:
  • 16i/18i/21i
  • 30i/31i/32i
  • Some 0i series controls

Good to know

Because support depends on the control configuration, always verify availability in the control manual.

Assigning Variable Names

There are two common ways to define SETVN aliases:

Method 1: Sequential Assignment

Multiple variable names can be assigned sequentially starting from a specific variable number.
SETVN 500 [RADIUS, ANGLE]
In this case:
  • #RADIUS refers to #500 and contain a null value be default
  • #ANGLE refers to #501 and contain a null value be default
Additional names would continue incrementing the variable number automatically.

Method 2: Individual Assignment

Variables can also be defined individually and assigned values at the same time.
SETVN 500 [RADIUS] = 60 SETVN 501 [ANGLE] = 15
This method both creates the alias and initializes the variable value.

Using Named Variables in a Program

Once defined, the variables are used exactly like normal macro variables:
X[COS[#ANGLE] * #RADIUS] Y[SIN[#ANGLE] * #RADIUS]
From a programming perspective, this behaves the same as writing:
X[COS[#501] * #500] Y[SIN[#501] * #500]
The difference is simply improved readability.

Deleting Variable Aliases

Aliases created with SETVN can be removed by executing the SETVN command without specifying names for the variables in the brackets.
Example:
SETVN 500 []
After deletion, the variables themselves still exist, the command only removes the assigned names (aliases).