---
title: "User frames: $MNUFRAME and the active UFRAME"
description: "Read the user frames $MNUFRAME of a Fanuc robot and watch the active UFRAME and UTOOL numbers ($MNUFRAMENUM, $MNUTOOLNUM) while a program runs, without a Karel program."
---

# User frames: $MNUFRAME and the active UFRAME

Which user frame is active while a Fanuc program runs, and what are its values? The user frames are the system variable `$MNUFRAME` and the active one is `$MNUFRAMENUM`. A PC reads them directly: no register to copy, no Karel program on the robot.

## The variables

| Variable | Type | Meaning | File |
| --- | --- | --- | --- |
| `$MNUFRAME[g,n]` | POSITION | User frame n of motion group g: X, Y, Z, W, P, R. n is 1 to 9 on a standard controller | `sysframe.va` |
| `$MNUFRAMENUM[g]` | BYTE | Number of the active user frame of group g | `sysframe.va` |
| `$MNUTOOLNUM[g]` | BYTE | Number of the active tool of group g | `sysframe.va` |

A TP program selects them with `UFRAME_NUM=n` and `UTOOL_NUM=n`. The variables give the numbers in use now.

## Read the user frames and watch the active numbers

`GetSysframeFile()` reads all the user frames in one request. Then the loop reads the two active numbers by name every second, through the web server of the controller.

**C# : UserFrameUframe**
```csharp
using System;
using System.Threading;
using UnderAutomation.Fanuc;
using UnderAutomation.Fanuc.Common;
using UnderAutomation.Fanuc.Common.Files.Variables;

public class UserFrameUframe
{
    static void Main()
    {
        FanucRobot robot = new FanucRobot();
        var parameters = new ConnectionParameters("192.168.0.1");
        parameters.Ftp.Enable = true;
        parameters.Cgtp.Enable = true;
        robot.Connect(parameters);

        /**/
        // The user frames of group 1: $MNUFRAME[1,n] is Mnuframe[0, n - 1]
        SysframeFile frames = robot.Ftp.KnownVariableFiles.GetSysframeFile();
        for (int n = 1; n <= frames.Mnuframe.GetLength(1); n++)
        {
            CartesianPositionVariable uf = frames.Mnuframe[0, n - 1];
            if (uf != null) Console.WriteLine($"UFRAME {n}: X={uf.X} Y={uf.Y} Z={uf.Z} W={uf.W} P={uf.P} R={uf.R}");
        }

        // Watch the active numbers while a program runs
        while (true)
        {
            int uframe = robot.Cgtp.ReadVariable("$MNUFRAMENUM[1]").IntegerValue;
            int utool = robot.Cgtp.ReadVariable("$MNUTOOLNUM[1]").IntegerValue;
            Console.WriteLine($"{DateTime.Now:T} UFRAME {uframe} UTOOL {utool}");
            Thread.Sleep(1000);
        }
        /**/
    }
}
```

**Python : UserFrameUframe**
```python
import time
from datetime import datetime

from underautomation.fanuc.fanuc_robot import FanucRobot
from underautomation.fanuc.connection_parameters import ConnectionParameters

robot = FanucRobot()
parameters = ConnectionParameters("192.168.0.1")
parameters.ftp.enable = True
parameters.cgtp.enable = True
robot.connect(parameters)

##
# The user frames of group 1 (one flat list, group 1 first)
frames = robot.ftp.known_variable_files.get_sysframe_file()
per_group = len(frames.mnuframe) // len(frames.mnuframenum)
for n, uf in enumerate(frames.mnuframe[:per_group], start=1):
    print(f"UFRAME {n}: X={uf.x} Y={uf.y} Z={uf.z} W={uf.w} P={uf.p} R={uf.r}")

# Watch the active numbers while a program runs
while True:
    uframe = robot.cgtp.read_variable("$MNUFRAMENUM[1]").integer_value
    utool = robot.cgtp.read_variable("$MNUTOOLNUM[1]").integer_value
    print(f"{datetime.now():%H:%M:%S} UFRAME {uframe} UTOOL {utool}")
    time.sleep(1)
##
```

The .NET array starts at 0: `$MNUFRAME[1,3]` is `Mnuframe[0, 2]`. In Python, `mnuframe` is one flat list with the user frames of group 1 first.

Log the numbers with the name of the running program (see [Monitor task execution](/fanuc/documentation/monitor-task-execution)): you see which frame and which tool each program uses, without opening it on the pendant.

## Read or write one user frame with RMI

With the RMI option (R912), `ReadUFrame(n)` and `WriteUFrame(n, frame)` read and write one user frame, `GetUFrameUTool()` and `SetUFrameUTool()` read and set the active numbers.

**C# : RmiFramesIoFrames**
```csharp
using System;
using UnderAutomation.Fanuc;
using UnderAutomation.Fanuc.Common;
using UnderAutomation.Fanuc.Rmi.Data;

public class RmiFramesIoFrames
{
    static void Main()
    {
        FanucRobot robot = new FanucRobot();
        ConnectionParameters parameters = new ConnectionParameters("192.168.0.1");
        parameters.Rmi.Enable = true;
        robot.Connect(parameters);

        /**/
        // Read UFRAME 1
        RmiIndexedFrameResponse uf = robot.Rmi.ReadUFrame(1);
        Console.WriteLine($"UFrame 1: X={uf.Frame.X:F1}  Y={uf.Frame.Y:F1}  Z={uf.Frame.Z:F1}");

        // Write UFRAME 1
        robot.Rmi.WriteUFrame(1, new XYZWPRPosition { X = 100, Y = 0, Z = 0, W = 0, P = 0, R = 0 });

        // Read UTOOL 1
        RmiIndexedFrameResponse ut = robot.Rmi.ReadUTool(1);
        Console.WriteLine($"UTool 1: X={ut.Frame.X:F1}  Y={ut.Frame.Y:F1}  Z={ut.Frame.Z:F1}");

        // Write UTOOL 1
        robot.Rmi.WriteUTool(1, new XYZWPRPosition { X = 0, Y = 0, Z = 200, W = 0, P = 0, R = 0 });

        // Get current UFRAME and UTOOL numbers
        RmiUFrameUToolNumbersResponse current = robot.Rmi.GetUFrameUTool();
        Console.WriteLine($"Active UFRAME={current.Frame}  UTOOL={current.Tool}");

        // Set the active UFRAME and UTOOL
        robot.Rmi.SetUFrameUTool(uframe: 1, utool: 2);
        /**/

        robot.Disconnect();
    }
}
```

**Python : RmiFramesIoFrames**
```python
from underautomation.fanuc.fanuc_robot import FanucRobot
from underautomation.fanuc.connection_parameters import ConnectionParameters
from underautomation.fanuc.common.xyzwpr_position import XYZWPRPosition

robot = FanucRobot()
parameters = ConnectionParameters("192.168.0.1")
parameters.rmi.enable = True
robot.connect(parameters)

##
# Read UFRAME 1
uf = robot.rmi.read_u_frame(1)
print(f"UFrame 1: X={uf.frame.x:.1f}  Y={uf.frame.y:.1f}  Z={uf.frame.z:.1f}")

# Write UFRAME 1
frame_pos = XYZWPRPosition()
frame_pos.x = 100
robot.rmi.write_u_frame(1, frame_pos)

# Read UTOOL 1
ut = robot.rmi.read_u_tool(1)
print(f"UTool 1: X={ut.frame.x:.1f}  Y={ut.frame.y:.1f}  Z={ut.frame.z:.1f}")

# Write UTOOL 1
tool_pos = XYZWPRPosition()
tool_pos.z = 200
robot.rmi.write_u_tool(1, tool_pos)

# Get current UFRAME and UTOOL numbers
current = robot.rmi.get_u_frame_u_tool()
print(f"Active UFRAME={current.frame}  UTOOL={current.tool}")

# Set the active UFRAME and UTOOL
robot.rmi.set_u_frame_u_tool(uframe=1, utool=2)
##

robot.disconnect()
```

## The current position in a user frame

SNPX gives the current position of the robot in a user frame of your choice, with `ReadUserFramePosition(n)`. See [SNPX current position](/fanuc/documentation/snpx-position).

## Cautions

- A taught point keeps the number of its user frame, not the values of the frame. Change a user frame and every Cartesian point taught in it moves with it. This is what a user frame is for (move a fixture, teach the frame again), and also what breaks a cell when the wrong frame is changed.
- Keep a copy of `sysframe.va` before you change a frame. See [Back up and compare the frames of a fleet](/fanuc/documentation/fanuc-backup-compare-frames-fleet).

## Without code

[TouchUp](/touchup), the robot workbench for VS Code, shows the user frames 1 to 9 and the active user frame of a connected Fanuc controller, or of a backup, as a table and in 3D. It reads them only: it does not write a user frame in this version. See [User frames and tools](/touchup/documentation/user-frames-and-tools).

## See also

- [Fanuc system variables list](/fanuc/documentation/fanuc-system-variables-list)
- [Tool frames: $MNUTOOL and $MNUTOOLNUM](/fanuc/documentation/fanuc-tool-frame-utool)
- [CGTP registers & variables](/fanuc/documentation/cgtp-registers-variables)
- [Frames & orientations](/fanuc/documentation/motion-frames-orientations)