Bootstrap Chameleon Logo

Take UI Snapshot

Take UI Snapshot

For Chameleon Tools created through TAPython, we can also use unreal.ChameleonData.snapshot_chameleon_window(json_path, override_window_size=override_size) to capture the content in the Chameleon window. The advantage of this command is that it can specify the window size, so it can capture the complete content even if the content in the window cannot be fully displayed. For example, in the Gallery tool, we captured the entire interface (over 5000 pixels high) at once.

A GIF showcasing a snapshot of the entire gallery tool with a single click

Calculate the Actual Window Size

In the process of calculating the actual maximum size of the window, some auxiliary functions can be used, such as:

  • unreal.ChameleonData.get_chameleon_window_size()

Can get the actual size of the current Chameleon window

  • chameleon_data_instance.get_top_scroll_box_offsets(json_path)

Get the size of the Offsets (Offset, ScrollOffsetOfEnd, ViewFraction, ViewOffsetFraction) in the topmost ScrollBox of the Chameleon tool

Calculate the size of all content in the entire ScrollBox using parameters such as Offset, ScrollOffsetOfEnd, ViewFraction, ViewOffsetFraction. Then use SnapshotChameleonWindow to capture the entire tool window's content, including the unshown part in the ScrollBox, by setting override_window_size.

For example, the following code first calculates the size of the interface when fully displayed and then performs a screenshot operation.

```Python def snapshot(json_path): data = unreal.PythonBPLib.get_chameleon_data(json_path) current_size = unreal.ChameleonData.get_chameleon_window_size(json_path) scrollbox_offsets = data.get_top_scroll_box_offsets(json_path) if scrollbox_offsets and "ScrollOffsetOfEnd" in scrollbox_offsets: height_full = scrollbox_offsets["ScrollOffsetOfEnd"] / (1.0 - scrollbox_offsets["viewFraction"]) height_full += 48 override_size = (current_size.x, round(height_full)) else: override_size = (0, 0) # current size r = unreal.ChameleonData.snapshot_chameleon_window(json_path, override_window_size=override_size) print(f"Save UI: {r}")

<b>CAUTION</b><br>The code above does not take into account the influence of `DPIScale` (default is 1). It needs to be modified when using a high-resolution screen and enabling DPI.
{: .alert .alert-warning}

For situations where the current topmost ScrollBox is known, you can use [get_scroll_box_offsets](https://www.tacolor.xyz/pages/ChameleonDataAPI.html#get_scroll_box_offsets to get the size of the Offsets (Offset, ScrollOffsetOfEnd, ViewFraction, ViewOffsetFraction) of the ScrollBox.

For example:

```Python
def get_full_size_of_this_chameleon(self):
    current_size = unreal.ChameleonData.get_chameleon_window_size(self.jsonPath)
    scrollbox_offsets = self.data.get_scroll_box_offsets(self.ui_scrollbox)
    height_full = scrollbox_offsets["ScrollOffsetOfEnd"] / (1.0 - scrollbox_offsets["viewFraction"])
    height_full += 48   # add title bar
    return current_size.x, round(height_full)

def on_button_Snapshot_click(self):
    full_size = self.get_full_size_of_this_chameleon()
    saved_file_path = unreal.ChameleonData.snapshot_chameleon_window(self.jsonPath, unreal.Vector2D(*full_size))

    if saved_file_path:
        unreal.PythonBPLib.notification(f"UI Snapshot Saved:", hyperlink_text = saved_file_path
                                        , on_hyperlink_click_command = f'chameleon_gallery.explorer("{saved_file_path}")')
    else:
        unreal.PythonBPLib.notification(f"Save UI snapshot failed.", info_level = 1)

TIP
The maximum interface length that can be captured in Unreal Engine is 16384. Our screenshot function also uses the Viewport feature, so it is also subject to the #define MAX_VIEWPORT_SIZE 16384 code restriction.

Set Scroll Bar Position

In addition, if we need to set the position of the scroll bar, we can use the following function:

Add Screenshot Function to All Chameleon Tools

In UE5, we can add a screenshot function to all Chameleon tools through the "OnTabContextMenu" field in MenuConfig.ini. For example:

MenuConfig.ini

"OnTabContextMenu":{
    "name": "TA Python Tab",
    "items": [
        {
            "name": "Save UI Snapshot",
            "command": "import Utilities; Utilities.snapshot_chameleon.snapshot(%tool_path)"
        }
    ]
}

Where Utilities.snapshot_chameleon.snapshot(%tool_path) is the snapshot function at the beginning of this article.

Capture Object Detail Panel Content

Other screenshot functions include PythonBPLib's snapshot_details, which can be used to capture the content of the object detail panel.

unreal.PythonBPLib.snapshot_details(start_from_docking, override_window_size=[0.000000, 0.000000], image_file_path="")