> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/hypersim/automation-api-and-scripting/python-dashboard-api.md).

# Dashboard API

## Overview

The **Python Dashboards application**, developed by OPAL-RT, provides a **REST API** (HTTP-based) that enables communication between the user interface (UI) and the backend server.

The **Extended Python API for Dashboards** acts as a wrapper around this REST API, allowing users to interact with the backend server through Python scripts. In this context, a Python script functions as an additional client “yet another client” —similar to the Dashboards UI—providing a flexible and programmatic way to access and control the system.

The Python Dashboard API is divided in two packages:

* [**opalone.configuration**](https://www.opal-rt.com/docs/hypersim/automation-api-and-scripting/python-dashboard-api/api-reference/opalone.configuration.md): contains various modules to configure the API, either programmatically or via command-line arguments.
* [**opalone.api**](https://www.opal-rt.com/docs/hypersim/automation-api-and-scripting/python-dashboard-api/api-reference/opalone.api.md): contains the API functions and definitions.

### Requirements

You must have a functional Python interpreter (**version 3.7 or later**) installed on your machine, with the **pip tool** available in your system’s PATH environment variable.

If you encounter issues with your Python or pip setup, refer to the official pip documentation for troubleshooting guidance.

### Install the wheel files to your IDE

The Dashboards installation includes a set of [Python wheel packages](https://realpython.com/python-wheels/) that can be installed in the Python environment of your choice. These wheel files are located in your Opal One installation directory.

To install the packages:

{% code overflow="wrap" lineNumbers="true" %}

```
python C:\OPAL-RT\OpalOne\<version>\api\client\python\install_opalone_api.py
```

{% endcode %}

where \<version> is the currently installed version of OpalOne.

{% hint style="info" %}
The Python API has two layers: a **high-level API** (documented here) built on top of a **low-level API**.

By default, “Python API” refers to the high-level API.

After installation, running pip list will show two OPAL-RT-related packages:

* **opalone**: the high-level API intended for user interaction (recommended)
* **opal-unified-api-client**: the low-level API, not intended for direct use
  {% endhint %}

## Examples

### Print information about datapoints of a given project

{% code overflow="wrap" lineNumbers="true" %}

```
python print_datapoints_example.py <name>
```

{% endcode %}

\<name> is the name of the open project in HYPERSIM

<details>

<summary><strong>Python code: print_datapoints_example.py</strong></summary>

{% code overflow="wrap" lineNumbers="true" %}

```python
"""print_datapoints_example.py -- Print information about datapoints of a given project

Usage:
    python print_datapoints_example.py <name>

- name: The name of an open project in RT-LAB

This example script will print information to the screen about
datapoints of a given project. More specifically, for
each datapoint found:
- its type
- its data type
- its path in the project

The type can either be "PARAMETER" or it can be various kind
of signals: "COMMAND", "DISPLAY", "MULTI_DISPLAY", "OUTPUT", "INPUT", "IO_INPUT", "IO_OUTPUT".

The data_type shows what kind of data this datapoint contains.
the possibilities are:
- BOOLEAN (a logical 0 or 1)
- INTEGER (a natural integer)
- REAL (a floating point number)
- NUMERIC (a combination of the three above)
- ENUM (an integer-like of mutually-exclusive values)
- COLOR (a RGB color code)
- STRING (a chain of characters, can be any length)
- FILE (a pointer to a file stored in the backend server)

The path gives the information about where this datapoint is
in the project, whether it is in a block inside a subsystem
of a model, or in a widget on a panel, etc. The path is what
makes each datapoint unique amongst each other.

For information on how to setup the opalone Python package
into your favorite Python, please refer to the Dashboards user manual:
https://www.opal-rt.com/docs/rt-lab/automation-api-and-scripting/python-dashboard-api

(c) OPAL-RT Technologies 2023
"""

import sys

###### UNCOMMENT THIS PART IF YOU ARE NOT USING IT DIRECTLY IN THE DASHBOARD (External Environment) ######

# from opalone.configuration import options # Uncomment here

### YOU SHOULD CHOOSE THE CORRECT VERSION AND CORRECT PLATFORM ###

# options.use_rtlab("v2024.4.0.RTLAB_4069.7") # Uncomment here if the platform is RT-LAB, and replace this version with the correct one
# options.use_hypersim("v2024.4.x.master.4615") # Uncomment here if the platform is HYPERSIM, and replace this version with the correct one

###### ---------------------------------------------------------- ######

try:
    from opalone.api import get_project_by_name
    from opalone.api import DatapointType
    from opalone.exceptions import ApiException
except ImportError as ex:
    print(str(ex))
    print("The Opal One Python API seems to not be installed in this Python environment.")
    print("To install it, please refer to the Dashboards section:")
    print("https://www.opal-rt.com/docs/rt-lab/automation-api-and-scripting/python-dashboard-api")
    print(f"For information, the current Python is found at this location {sys.executable}")
    sys.exit(1)

type_header = "TYPE"
data_type_header = "DATATYPE"
path_header = "PATH"
column_spacing = " <12"


def print_table_row(type, data_type, path):
    print(f"{type:{column_spacing}}{data_type:{column_spacing}}{path}")


def print_table_header():
    print_table_row(type_header, data_type_header, path_header)


def print_dashed_line():
    print(80*'-')


def usage_and_exit():
    print(__doc__)
    sys.exit()


def main(project_name):
    datapoints = dict()

    # get_project_by_name is a function from the opalone package
    # that returns a "Project" instance that matches the given
    # project name.
    try:
        my_project = get_project_by_name(project_name)
    except ApiException as ex:
        print(f"!ERROR! : {ex}")
        print_dashed_line()
        usage_and_exit()
    else:
        # Accessing datapoints contained in the project using the "datapoints"
        # property of the project. This property returns a dictionary, which can
        # be traversed to use each datapoint, search for one in particular, etc.
        datapoints = my_project.datapoints

    print(f"Listing of datapoints in project {project_name}:")
    print_table_header()
    print_dashed_line()

    parameters = 0
    signals = 0
    for path, dp in sorted(datapoints.items()):
        print_table_row(dp.type, dp.data_type, path)
        if dp.type == DatapointType.PARAMETER:
            parameters = parameters + 1
        else:
            signals = signals + 1

    print_dashed_line()
    print(f"Number of datapoints in project: {len(datapoints)} ({parameters} Parameters, {signals} Signals)")


if __name__ == "__main__":
    if len(sys.argv) < 2:
        usage_and_exit()
    main(sys.argv[1])
```

{% endcode %}

</details>

### A step by step example to generate a panel for a project

Before using this code, ensure the following setup is completed:

1. Create a new project in HYPERSIM using any name of your choice,
2. Compile the project
3. Once compilation is complete, launch the **Dashboards UI** from HYPERSIM.
4. In the left-hand navigation pane, select your model and confirm that the datapoints are displayed.
5. Ensure that the model status is **“Loadable”**, indicating that compilation was successful.

{% code overflow="wrap" lineNumbers="true" %}

```
python panel_creation_example.py
```

{% endcode %}

<details>

<summary><strong>Python code: panel_creation_example.py</strong></summary>

{% code overflow="wrap" lineNumbers="true" %}

```python
"""panel_creation_example.py - A step by step example to generate a panel for a project

Usage:
    python panel_creation_example.py

This example script demonstrates the usage of the Python API
in order to create a panel and visualize data.

This script is interactive.  It will ask the user to enter inputs
as it runs. The end result will be a panel with a few widgets
connected to datapoints of a model.

For information on how to setup the opalone Python package
into your favorite Python, please refer to the Dashboards user manual:
https://www.opal-rt.com/docs/rt-lab/simulation-control-monitoring-and-logging/interact-using-dashboards

(c) OPAL-RT Technologies 2023
"""

import sys

###### UNCOMMENT THIS PART IF YOU ARE NOT USING IT DIRECTLY IN THE DASHBOARD (External Environment) ######

# from opalone.configuration import options # Uncomment here

### YOU SHOULD CHOOSE THE CORRECT VERSION AND CORRECT PLATFORM ###

# options.use_rtlab("v2024.4.0.RTLAB_4069.7") # Uncomment here if the platform is RT-LAB, and replace this version with the correct one
# options.use_hypersim("v2024.4.x.master.4615") # Uncomment here if the platform is HYPERSIM, and replace this version with the correct one

###### ---------------------------------------------------------- ######

try:
    from opalone.api import get_project_by_name
    from opalone.api import BoardType
    from opalone.exceptions import ApiException
except ImportError as ex:
    print(str(ex))
    print("The Opal One Python API seems to not be installed in this Python environment.")
    print("To install it, please refer to the Dashboards user manual:")
    print("https://www.opal-rt.com/docs/rt-lab/automation-api-and-scripting/python-dashboard-api")
    print(f"For information, the current Python is found at this location {sys.executable}")
    sys.exit(1)


def before():
    print("Opal One Python API - Example script to generate a panel")
    print("""Before continuing, please make sure you have done the following:
    - Create a project in RT-LAB, with any name you want, and use basic/rtdemo1 as a template project.
    - Compile the rtdemo1 model for simulation on localhost (Windows) with your preferred version of Matlab.
    - When compilation is done, open the Dashboards UI from RT-LAB.
    - In the navigation pane on the left, click on your model's name and check that the model's datapoints are showing.
    - Check that the model state is "Loadable" since the model was compiled in RT-LAB.""")
    wait_user()
def wait_user():
    input("Press <Enter> to continue...")


def yes(question):
    return input(f"{question} (Y/N) ").lower().startswith("y")

def recursive_panel_add(project, panel_name, idx):
    try:
        return project.add_board(BoardType.PANEL, f"{panel_name} ({idx})")
    except ApiException:
        if idx > 500:
            raise Exception("Could not create panel after 500 attempts.")
        return recursive_panel_add(project, panel_name, idx+1)

def main():
    before()

    print("First, we will execute the function 'get_project_by_name(<name of your project>)' to get a Project object")
    project_name = input("Enter the name of your RT-LAB project: ")
    project = get_project_by_name(project_name)
    print(f"The project's name is: {project.name}")

    panel_name = "My Control Panel"
    print("Now we will create a panel object by running the function 'project.add_board(BoardType.PANEL, 'My Control Panel')'.")
    try:
        panel = project.add_board(BoardType.PANEL, panel_name)
    except ApiException:
        print(f"It seems a panel called {panel_name} already exists.")
        if yes("Do you want to delete that panel?"):
            project.boards[panel_name].delete()
            panel = project.add_board(BoardType.PANEL, panel_name)
        else:
            panel = recursive_panel_add(project, panel_name, 1)

    print("Panel added!")
    print(f"In the Dashboards UI navigation pane, click on '{panel.name}'.")
    wait_user()

    print("Now we will add widgets in the panel by running the function 'panel.add_multiple_widget([<widget_paths>])'.")
    print("After that, to put the widgets in a desired location we will iterate over the widgets and set their location property.")
    print("for i, w in enumerate(widgets):")
    print("    w.location = f'({150*i},200)'")
    wait_user()

    widgets = panel.add_multiple_widget(
        ["Widget Library/Commands/Numeric Control",
         "Widget Library/Commands/Slider",
         "Widget Library/Displays/Numeric Display",
         "Widget Library/Displays/Gauge"])

    for i, w in enumerate(widgets):
        w.location = f"({150*i},200)"
    
    print("You should now see 4 widgets on the panel: a numeric control, a slider, a numeric display and a gauge.")
    print("You can click the 'Fit to screen' button (bottom right of the main area of the UI) to better center the widgets on your screen.")
    wait_user()

    print("Now we will set some properties on the widgets by running 'panel.datapoints[<widget_name>/<property_name>].value = <value>'.")
    print("(E.g. panel.datapoints['control1/Background'].value = [0, 0xff, 0xcc, 0.35])")
    widgets[3].dimensions = "100 100"
    panel_datapoints = panel.datapoints
    panel_datapoints['control1/Background'].value = [0, 0xff, 0xcc, 0.35]
    panel_datapoints['display1/Background'].value = [0, 0xaa, 0xff, 0.35]
    panel_datapoints['gauge1/Minimum'].value = -100
    panel_datapoints['gauge1/Maximum'].value = 300
    panel_datapoints['gauge1/Lower limit'].value = -20
    panel_datapoints['gauge1/Upper limit'].value = 250
    panel_datapoints['slider1/Maximum'].value = 100
    panel_datapoints['slider1/Thumb'].value = [0xff, 0, 0, 1]
    wait_user()

    print("You can see on the panel that some properties of the widgets have changed.")
    print("You can click the on any of the widget to have its properties sidebar showing.")
    wait_user()

    print("Now we will do some connections to the model.")
    print("We will start by getting the model's datapoints by accessing the 'models' property of the project object: 'project.models[<model_name>].datapoints'.")
    model = project.models['rtdemo1']
    model_datapoints = model.datapoints
    wait_user()

    print("Connecting the Gain Kp from the model to the slider on the panel by running the line 'model_datapoints['sm_computation/Gain Kp/Gain'].connect_to(panel_datapoints['slider1/Data'])'.")
    model_datapoints['sm_computation/Gain Kp/Gain'].connect_to(panel_datapoints['slider1/Data'])
    wait_user()

    print("Connecting the Gain Ki from the model to the numeric control on the panel")
    model_datapoints['sm_computation/Gain Ki/Gain'].connect_to(panel_datapoints['control1/Data'])
    wait_user()

    print("Connecting the controller output signal from the model to the gauge on the panel")
    model_datapoints['sm_computation/Integrator1/port1'].connect_to(panel_datapoints['gauge1/Data'])
    wait_user()

    print("Connecting the plant output signal from the model to the numeric display on the panel")
    model_datapoints['sm_computation/Integrator3/port1'].connect_to(panel_datapoints['display1/Data'])
    wait_user()

    print("That's it! You have connected datapoints programmatically.")
    print("You can now run the model and see it in action. You can also open the Simulink console of the model to control the reference target.")
    print("Features from the Simulink console will gradually be replaced by equivalent features in Dashboards as it evolves.")
    input("Press <Enter> to terminate the script...")


if __name__ == "__main__":
    main()
```

{% endcode %}

</details>

### Run model simulations of a given project

{% code overflow="wrap" lineNumbers="true" %}

```
python simulations_example.py <name>
```

{% endcode %}

\<name> is the name of the open project in HYPERSIM

<details>

<summary><strong>Python code: simulations_example.py</strong></summary>

{% code overflow="wrap" lineNumbers="true" %}

```python
"""simulations_example.py -- Run model simulations of a given project

Usage:
    python simulations_example.py <name>

- name: The name of an open project in RT-LAB

This example script will print run, pause and stop the models of a given project.
Between each operation, the model states are printed to the screen.

Expected states are LOADABLE, then RUNNING, then PAUSED, then back to LOADABLE.

For this script to work, your models must first be compiled in RT-LAB.

For information on how to setup the opalone Python package
into your favorite Python, please refer to the Dashboards user manual:
https://opal-rt.atlassian.net/wiki/spaces/PDASH

(c) OPAL-RT Technologies 2023
"""

import time
import sys

###### UNCOMMENT THIS PART IF YOU ARE NOT USING IT DIRECTLY IN THE DASHBOARD (External Environment) ######

# from opalone.configuration import options # Uncomment here

### YOU SHOULD CHOOSE THE CORRECT VERSION AND CORRECT PLATFORM ###

# options.use_rtlab("v2024.4.0.RTLAB_4069.7") # Uncomment here if the platform is RT-LAB, and replace this version with the correct one
# options.use_hypersim("v2024.4.x.master.4615") # Uncomment here if the platform is HYPERSIM, and replace this version with the correct one

###### ---------------------------------------------------------- ######

try:
    from opalone.api import get_project_by_name
except ImportError as ex:
    print(str(ex))
    print("The Opal One Python API seems to not be installed in this Python environment.")
    print("To install it, please refer to the Dashboards section:")
    print("https://www.opal-rt.com/docs/rt-lab/automation-api-and-scripting/python-dashboard-api")
    print(f"For information, the current Python is found at this location {sys.executable}")
    sys.exit(1)


def usage_and_exit():
    print(__doc__)
    sys.exit()


def print_model_states(project):
    for name, model in project.models.items():
        print(f"{name}: {model.state}")


def main(project_name):
    project = get_project_by_name(project_name)

    print("Before running models:")
    print_model_states(project)

    project.run_all_models()
    print("After running models:")
    print_model_states(project)

    time.sleep(5)
    project.pause_all_models()
    print("After pausing models:")
    print_model_states(project)

    time.sleep(5)
    project.stop_all_models()
    print("After stopping models:")
    print_model_states(project)


if __name__ == "__main__":
    if len(sys.argv) < 2:
        usage_and_exit()
    main(sys.argv[1])
```

{% endcode %}

</details>

### Export a panel to a JSON file

Please review the following considerations before using the script:

**Export Location**

* By default, the panel is exported to a folder within the project directory.
* If needed, you can override this by specifying a **CUSTOM\_EXPORT\_PATH.**

**Script Environment**

* In a **Dashboards environment**, the current project is detected automatically.
* In an **external environment**, you must define PROJECT\_PATH to locate the project containing the panel to export.

{% code overflow="wrap" lineNumbers="true" %}

```
python export_panel_example.py
```

{% endcode %}

<details>

<summary><strong>Phyton code: export_panel_example.py</strong></summary>

{% code overflow="wrap" lineNumbers="true" %}

```python
"""Export Panel 

This script demonstrates using the Python API to export a panel into a folder. 
Contents of the export folder include:
- A JSON file containing panel widgets and connections
- Image files of the panel if applicable

Export Location: 
- By default, the panel exports to the project path. 
- You may specify CUSTOM_EXPORT_PATH if needed. 

Script Environment:
- In a Dashboards environment, the current project is retrieved automatically. 
- In an external environment, specify PROJECT_PATH to retrieve the project containing the panel to export.  
- In an external environment, uncomment the required section below and add the correct version of your RT-LAB (e.g., v2024.4.0.1)

For more information on using the Python API, refer to the documentation:
https://www.opal-rt.com/docs/rt-lab/automation-api-and-scripting/python-dashboard-api

(c) OPAL-RT Technologies 2024
"""

import json
import os
from sys import exit
from opalone.api import BoardType, get_current_project, get_project_by_path
from opalone.exceptions import EnvironmentException, NotFoundException

PANEL_NAME_TO_EXPORT = "Panel rtdemo1"
CUSTOM_EXPORT_PATH = None # r"C:\...REPLACE ME AS NEEDED" 
PROJECT_PATH = None # r"C:\...REPLACE ME AS NEEDED"

###### UNCOMMENT THIS PART IF YOU ARE NOT USING IT DIRECTLY IN THE DASHBOARD (External Environment) ######

# from opalone.configuration import options # Uncomment here

### YOU SHOULD CHOOSE THE CORRECT VERSION AND CORRECT PLATFORM ###

# options.use_rtlab("v2024.4.x.master.4615") # Uncomment here if the platform is RT-LAB, and replace this version with the correct one
# options.use_hypersim("v2024.4.x.master.4615") # Uncomment here if the platform is HYPERSIM, and replace this version with the correct one

###### ---------------------------------------------------------- ######

def export_panel(project, panel, folder_path):
    print("Exporting panel")

    if panel.type != BoardType.PANEL:
        print("Board to export should be a Panel")
        exit(1)

    panel_data = {
        "name": panel.name,
        "description": panel.description,
        "is_grid_visible": panel.is_grid_visible,
        "position": panel.position,
        "scale": panel.scale,
        "widgets": [],
        "connections": []
    }

    # Export all widgets in the panel
    print("Exporting widgets and files")
    for w in panel.widgets.values():

        try: 
            library_path = w.library_path
        except:
            print(f"Skipping widget - currently unsupported by Python API: id={w.id} description={w.description}")
            continue

        widget_data = {
            "name": w.name,
            "angle": w.angle,
            "dimensions": w.dimensions,
            "flip_state": w.flip_state,
            "is_label_visible": w.is_label_visible,
            "is_locked": w.is_locked,
            "location": w.location,
            "path": None,
            "parameters": []
        }

        widget_data["path"] = library_path

        for p in w.parameters.values():
            if not p.is_visible:
                continue
            parameter = {
                "name": p.name,
                "data_type": p.data_type
            }
            if p.data_type == "FILE":
                if p.value is not None:
                    parameter["value"] = p.value.name
                    project.files[p.value.name].download(folder_path)
                else:
                    parameter["value"] = ""
            else:
                parameter["value"] = p.value
            widget_data["parameters"].append(parameter)

        panel_data["widgets"].append(widget_data)

    # Export all connections
    print("Exporting connections")

    for c in project.connections:
        if str(c.destination.path).startswith(panel_data["name"] + "/"):
            connection = {
                # Connection Datapoints may be accessed through source and destination properties
                "modelPath": c.source.path,
                "panelPath": c.destination.path,
                "enabled": c.enabled
            }
            panel_data["connections"].append(connection)

    os.makedirs(folder_path, exist_ok=True)

    file_path  = os.path.join(folder_path, "panel.json")
    with open(file_path, 'w', encoding='utf-8') as f:
        json.dump(panel_data, f, ensure_ascii=False, indent=2)

    print(f'Panel "{panel.name}" exported at "{folder_path}"')

# Retrieve project containing the panel to export
try:
    # If script is run from Dashboards environment, you may retrieve the project automatically
    project = get_current_project()
    print(f'Project with name "{project.name}" found in environment')

except EnvironmentException as e:
    # If script is run from external environment, you must provide the PROJECT_PATH
    print(e)
    try:
        project = get_project_by_path(PROJECT_PATH)
    except NotFoundException as e:
        print(f"No project was found in the specified PROJECT_PATH: {PROJECT_PATH}")
        exit(1)

# Retrieve panel to export 
try: 
    panel = project.boards[PANEL_NAME_TO_EXPORT]
    print(f'Panel with name "{panel.name}" found')
except KeyError:
    print(f'Panel with name "{PANEL_NAME_TO_EXPORT}" not found in the project')
    exit(1)

# Export location 
if CUSTOM_EXPORT_PATH == None:
    project_root, _ = os.path.split(project.path)
    folder_path = os.path.join(project_root, PANEL_NAME_TO_EXPORT)
else:
    folder_path = os.path.join(CUSTOM_EXPORT_PATH, PANEL_NAME_TO_EXPORT)

folder_path = os.path.normpath(folder_path)

try:
    export_panel(project, panel, folder_path)
except Exception as e:
    print(f"An error occurred during panel export: {e}")
    exit(1)
```

{% endcode %}

</details>

### **Import a panel from a JSON file**

Please review the following considerations before using the script:

**Import Location**

* By default, the panel to import must be located within the project directory.
* If needed, you can override this by specifying a **CUSTOM\_IMPORT\_PATH**.

**Script Environment**

* In a **Dashboards environment**, the current project is detected automatically.
* In an **external environment**, you must define PROJECT\_PATH to locate the project containing the panel to import.

{% code overflow="wrap" lineNumbers="true" %}

```
python import_panel_example.py
```

{% endcode %}

<details>

<summary><strong>Phyton code: import_panel_example.py</strong></summary>

{% code overflow="wrap" lineNumbers="true" %}

```python
"""Import Panel 

This script demonstrates using the Python API to import a panel from a folder into a project. 
Contents of the export folder include:
- A JSON file containing panel widgets and connections
- Image files of the panel if applicable

Import Location: 
- By default, the panel folder to import must be in project path. 
- You may specify CUSTOM_IMPORT_PATH if needed. 

Script Environment:
- In a Dashboards environment, the current project is retrieved automatically. 
- In an external environment, specify PROJECT_PATH to retrieve the project containing the panel to import.  
- In an external environment, uncomment the required section below and add the correct version of your RT-LAB (e.g., v2024.4.0.1)

For more information on using the Python API, refer to the documentation:
https://www.opal-rt.com/docs/rt-lab/automation-api-and-scripting/python-dashboard-api

(c) OPAL-RT Technologies 2024
"""

import json
import os
from sys import exit
from datetime import datetime
from opalone.exceptions import EnvironmentException, NotFoundException
from opalone.api import BoardType, get_current_project, get_project_by_path

PANEL_NAME_TO_IMPORT = "Panel rtdemo1"
CUSTOM_IMPORT_PATH = None # r"C:\...REPLACE ME AS NEEDED"  
PROJECT_PATH = None # r"C:\...REPLACE ME AS NEEDED"

###### UNCOMMENT THIS PART IF YOU ARE NOT USING IT DIRECTLY IN THE DASHBOARD (External Environment) ######

# from opalone.configuration import options # Uncomment here

### YOU SHOULD CHOOSE THE CORRECT VERSION AND CORRECT PLATFORM ###

# options.use_rtlab("v2024.4.x.master.4615") # Uncomment here if the platform is RT-LAB, and replace this version with the correct one
# options.use_hypersim("v2024.4.x.master.4615") # Uncomment here if the platform is HYPERSIM, and replace this version with the correct one

###### ---------------------------------------------------------- ######

def import_panel(project, folder_path):
    # Read JSON file
    print(f'Reading panel "{folder_path}" to import')
    file_path = os.path.join(folder_path, "panel.json")

    with open(file_path, 'r', encoding='utf-8') as file:
            panel_data = json.load(file)

    files = os.listdir(folder_path) 

    # Import files in the project if any
    if len(files) > 0:
        print("Importing files")
        for filename in files:
            if filename.endswith('.json'):
                project.add_file(os.path.join(file_path))

    # Add panel board
    print("Creating panel")
    time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    new_board_name  = f"{PANEL_NAME_TO_IMPORT} (imported at {time})"
    panel = project.add_board(BoardType.PANEL, new_board_name , panel_data["description"])
    panel.is_grid_visible = panel_data["is_grid_visible"]
    panel.position = panel_data["position"]
    panel.scale = panel_data["scale"]

    # Add widgets in the panel
    print("Importing panel widgets")
    for w in panel_data["widgets"]:
        widget = panel.add_widget(w["path"])
        widget.name = w["name"]
        widget.angle = w["angle"]
        widget.dimensions = w["dimensions"]
        widget.flip_state = w["flip_state"]
        widget.is_label_visible = w["is_label_visible"]
        widget.is_locked = w["is_locked"]
        widget.location = w["location"]
        for p in w["parameters"]:
            if p["data_type"] == "FILE" and p["value"]:
                widget.parameters[p["name"]].value = project.files[p["value"]]
            elif p["value"] != "":
                widget.parameters[p["name"]].value = p["value"]
    
    # Add connections
    print("Importing connections")
    datapoints = project.datapoints
    for c in panel_data["connections"]:
        model_path = c["modelPath"]
        panel_path = str(c["panelPath"]).replace(panel_data["name"], panel.name, 1)
        enabled = bool(c["enabled"])
        try:
            source = datapoints.get(model_path)
            destination = datapoints.get(panel_path)
            project.add_connection(source, destination, enabled)
        except Exception as e:
            print("Error connecting:")
            print(f"  {model_path} <-> {panel_path}")
            print(f"  Error: {e}")
            exit(1)

    print(f"Panel with name {new_board_name} imported successfully")

# Retrieve project containing the panel to import
try:
    # If the script is run from Dashboards environment, you may retrieve the project automatically
    project = get_current_project()
    print(f'Project with name "{project.name}" found in environment')

except EnvironmentException as e:
    # If script is run from external environment, you must use provide PROJECT_PATH
    print(e)

    try:
        project = get_project_by_path(PROJECT_PATH)
    except NotFoundException as e:
        print(f"No project was found in the specified PROJECT_PATH: {PROJECT_PATH}")
        exit(1)

if CUSTOM_IMPORT_PATH == None:
    project_root, _ = os.path.split(project.path)
    folder_path = os.path.join(project_root, PANEL_NAME_TO_IMPORT)
else:
    folder_path = os.path.join(CUSTOM_IMPORT_PATH, PANEL_NAME_TO_IMPORT)

folder_path = os.path.normpath(folder_path)

try:
    import_panel(project, folder_path)
except Exception as e:
    print(f"An error occurred during panel import: {e}")
    exit(1)
```

{% endcode %}

</details>

**Switch On/Off all LEDs on a panel**

Before using, please consider uncommenting the line that precise RT-LAB or HYPERSIM.

{% code overflow="wrap" lineNumbers="true" %}

```
python batch_update_leds.py
```

{% endcode %}

<details>

<summary><strong>Python code: batch_update_leds.py</strong></summary>

{% code overflow="wrap" lineNumbers="true" %}

```python
from opalone.api import get_project_by_name

PROJECT_NAME = 'rtdemo1'
PANEL_NAME = 'Panel (1)'

###### UNCOMMENT THIS PART IF YOU ARE NOT USING IT DIRECTLY IN THE DASHBOARD (External Environment) ######

# from opalone.configuration import options # Uncomment here

### YOU SHOULD CHOOSE THE CORRECT VERSION AND CORRECT PLATFORM ###

# options.use_rtlab("v2024.4.x.master.4615") # Uncomment here if the platform is RT-LAB, and replace this version with the correct one
# options.use_hypersim("v2024.4.x.master.4615") # Uncomment here if the platform is HYPERSIM, and replace this version with the correct one

###### ---------------------------------------------------------- ######

LED_BACKGROUND_OFF_COLOR = 'ffadad'
LED_BACKGROUND_ON_COLOR = 'bdb2ff'

def hex_to_rgba(hex_color: str) -> list[str]:
    hex_color = hex_color.lstrip('#')
    
    r = int(hex_color[0:2], 16)
    g = int(hex_color[2:4], 16)
    b = int(hex_color[4:6], 16)
    a = 1

    if len(hex_color) == 8:
        a = int(hex_color[6:8], 16) / 255

    return [r, g, b, a]

def batch_update_panel(panel_name: str, widget_type: str, parameter_key: str, parameter_value: str):
    project = get_project_by_name(PROJECT_NAME)
    board = project.boards[panel_name]

    for widget in board.widgets.values():
        if widget.library_path.endswith(widget_type):
            widget.parameters[parameter_key].value = parameter_value

batch_update_panel(PANEL_NAME, 'Displays/LED', 'Background (Off)', hex_to_rgba(LED_BACKGROUND_OFF_COLOR))
batch_update_panel(PANEL_NAME, 'Displays/LED', 'Background (On)', hex_to_rgba(LED_BACKGROUND_ON_COLOR))
```

{% endcode %}

</details>

### Batch changes (colors, values, dimensions…) via script

This script enables users to batch update the appearance of all widgets within a panel.

* Users can customize values (e.g., colors and dimensions) in the **User Settings** section at the beginning of the script.
* All defined changes are applied automatically to every widget in the panel.
* Parameters that have already been manually edited in the panel may be overwritten. **It is strongly recommended to back up your work.**
* Batch update sections are **commented out by default**—uncomment only the updates you wish to apply.
* Default values are based on the **Light theme**.

#### Usage

1. Ensure the **project name** and **panel name** match your environment.
2. Update the desired values in the **User Settings** section.
3. Uncomment the batch updates you want to apply.
4. Run the script to apply the selected changes to all widgets in the panel.

#### Customization Options

|            |                                                                        |
| ---------- | ---------------------------------------------------------------------- |
| COLORS     | Colors are defined as HEX.                                             |
| BOOLEAN    | Parameters: Those are either 0 or 1 (off or on)                        |
| DIMENSIONS | Dimensions are defined as “width height”.                              |
| RATIO      | This script can break ratios. Square widget should use width = height. |

<details>

<summary><strong>Python code: batch_update_all.py</strong></summary>

{% code overflow="wrap" lineNumbers="true" %}

```python
from opalone.api import get_project_by_name

"""
Script Name: Widget parameter batch 
Author: OPAL-RT Valentin Laurent & Romain Guilbault
Version: v1
Date: [2025-02-28]

Description:
This script allows users to batch modify the appearance of all widgets in a panel.
Users can customize values (such as colors and dimensions) at the beginning 
of the script, which will then be applied to all widgets automatically.

Notes:
- Parameters already edited in the panel will likely be reset. Backup your work.
- Batch changes are commented by default, uncomment the necessary batch changes.
- Light theme was used to define default values.

Usage:
1. Make the project name and panel name match those of your project.
2. Modify the default values in the "User Settings" section below.
3. Uncomment the batch update that should be done
4. Run the script to apply the uncommented batch changes to widgets in the panel.

Customization Options:
- COLORS: Colors are defined as HEX.
- BOOLEAN Parameters: Those are either 0 or 1 (off or on)
- DIMENSIONS: Dimensions are defined as "width height".
- RATIO: This script can break ratios. Square widget should use width = height.

"""

# --- Batch definitions ---
# These are the custom batchs that are called the change all parameters


def hex_to_rgba(hex_color: str) -> list[str]:
    hex_color = hex_color.lstrip('#')
    
    r = int(hex_color[0:2], 16)
    g = int(hex_color[2:4], 16)
    b = int(hex_color[4:6], 16)
    a = 1

    if len(hex_color) == 8:
        a = int(hex_color[6:8], 16) / 255

    return [r, g, b, a]

def batch_update_panel_parameters(panel_name: str, widget_type: str, parameter_key: str, parameter_value: str):
    project = get_project_by_name(PROJECT_NAME)
    board = project.boards[panel_name]

    for widget in board.widgets.values():
        if widget.library_path.endswith(widget_type):
            widget.parameters[parameter_key].value = parameter_value


def batch_update_panel_dimension(panel_name: str, widget_type: str, dimensions: str):
    project = get_project_by_name(PROJECT_NAME)
    board = project.boards[panel_name]

    for widget in board.widgets.values():
        if widget.library_path.endswith(widget_type):
            widget.dimensions = dimensions

# --- User Settings ---
# Modify these values to customize all widgets in the panel.

PROJECT_NAME = 'rtdemo1'
PANEL_NAME = 'Panel (1)'

# --- Numeric Control ---
# Uncomment needed batches

NUM_CONTROL_BUTTONS = '1' # Default = 1
NUM_CONTROL_BOLD = '0' # Default = 0
NUM_CONTROL_ITALIC = '0' # Default = 0
NUM_CONTROL_TEXT = '00B5D8' # Default = 00B5D8
NUM_CONTROL_BACKGROUND = '00ff00' # Default = FFFFFF
NUM_CONTROL_BORDER = '000000' # Default = 000000
NUM_CONTROL_DIMENSIONS = '100 20' # Default = 100 20

# batch_update_panel_parameters(PANEL_NAME, 'Numeric Control', 'Buttons', NUM_CONTROL_BUTTONS)
# batch_update_panel_parameters(PANEL_NAME, 'Numeric Control', 'Bold', NUM_CONTROL_BOLD)
# batch_update_panel_parameters(PANEL_NAME, 'Numeric Control', 'Italic', NUM_CONTROL_ITALIC)
# batch_update_panel_parameters(PANEL_NAME, 'Numeric Control', 'Text', hex_to_rgba(NUM_CONTROL_TEXT))
# batch_update_panel_parameters(PANEL_NAME, 'Numeric Control', 'Background', hex_to_rgba(NUM_CONTROL_BACKGROUND))
# batch_update_panel_parameters(PANEL_NAME, 'Numeric Control', 'Border', hex_to_rgba(NUM_CONTROL_BORDER))
# batch_update_panel_dimension(PANEL_NAME, 'Numeric Control', NUM_CONTROL_DIMENSIONS)

# --- knob ---
# Uncomment needed batches

KNOB_MIN = '-10' # Default = -10
KNOB_MAX = '10' # Default = 10
KNOB_DISPLAY = '1' # Default = 1
KNOB_FOREGROUND = 'F0F0F0' # Default = F0F0F0
KNOB_POINTER = '000000' # Default = 000000
KNOB_TICK = '000000' # Default = 000000
KNOB_SCALE = '000000' # Default = 000000
KNOB_DIMENSIONS = '60 60' # Default = '60 60' and should be equal.

# batch_update_panel_parameters(PANEL_NAME, 'Knob', 'Minimum', KNOB_MIN)
# batch_update_panel_parameters(PANEL_NAME, 'Knob', 'Maximum', KNOB_MAX)
# batch_update_panel_parameters(PANEL_NAME, 'Knob', 'Display', KNOB_DISPLAY)
# batch_update_panel_parameters(PANEL_NAME, 'Knob', 'Foreground', hex_to_rgba(KNOB_FOREGROUND))
# batch_update_panel_parameters(PANEL_NAME, 'Knob', 'Pointer', hex_to_rgba(KNOB_POINTER))
# batch_update_panel_parameters(PANEL_NAME, 'Knob', 'Tick Color', hex_to_rgba(KNOB_TICK))
# batch_update_panel_parameters(PANEL_NAME, 'Knob', 'Scale Color', hex_to_rgba(KNOB_SCALE))
# batch_update_panel_dimension(PANEL_NAME, 'Knob', KNOB_DIMENSIONS)

# --- Slider ---
# Uncomment needed batches

SLIDER_MIN = '0' # Default = 0
SLIDER_MAX = '10' # Default = 10
SLIDER_DISPLAY = '1' # Default = 1
SLIDER_BACKGROUND = 'F0F0F0' # Default = F0F0F0
SLIDER_FILL = 'B3B3B3' # Default = B3B3B3
SLIDER_THUMB = 'ffffff' # Default = ffffff
SLIDER_TICK = '000000' # Default = 000000
SLIDER_SCALE = '000000' # Default = 000000
SLIDER_DIMENSIONS = '20 240' # Default = '20 240' and 20 should not be changed.

# batch_update_panel_parameters(PANEL_NAME, 'Slider', 'Minimum', SLIDER_MIN)
# batch_update_panel_parameters(PANEL_NAME, 'Slider', 'Maximum', SLIDER_MAX)
# batch_update_panel_parameters(PANEL_NAME, 'Slider', 'Display', SLIDER_DISPLAY)
# batch_update_panel_parameters(PANEL_NAME, 'Slider', 'Background', hex_to_rgba(SLIDER_BACKGROUND))
# batch_update_panel_parameters(PANEL_NAME, 'Slider', 'Fill', hex_to_rgba(SLIDER_FILL))
# batch_update_panel_parameters(PANEL_NAME, 'Slider', 'Thumb', hex_to_rgba(SLIDER_THUMB))
# batch_update_panel_parameters(PANEL_NAME, 'Slider', 'Tick Color', hex_to_rgba(SLIDER_TICK))
# batch_update_panel_parameters(PANEL_NAME, 'Slider', 'Scale Color', hex_to_rgba(SLIDER_SCALE))
# batch_update_panel_dimension(PANEL_NAME, 'Slider', SLIDER_DIMENSIONS)

# --- Switch ---
# Uncomment needed batches

SWITCH_SHAPE = '0' # Toggle = 0, Flip = 1, Rocker = 2, Checkbox = 3
SWITCH_VALUE_OFF = '0' # Default = 0
SWITCH_VALUE_ON = '1' # Default = 1

SWITCH_BACKGROUND_OFF = 'CCCCCC' # Default = CCCCCC to be used with Toggle Shape
SWITCH_BACKGROUND_ON = '008200' # Default = 008200 to be used with Toggle Shape
SWITCH_THUMB = 'ffffff' # Default = ffffff to be used with Toggle Shape

SWITCH_FLIP = 'ffffff' # Default = ffffff to be used with Flip Shape
SWITCH_BASE = 'ffffff' # Default = ffffff to be used with Flip Shape

SWITCH_ROCKER = 'ffffff' # Default = ffffff to be used with Rocker Shape
SWITCH_BACKGROUND = 'ffffff' # Default = ffffff to be used with Rocker and Checkbox Shape

SWITCH_CHECKMARK = '2489d1' # Default = 2489d1 to be used with Checkbox Shape
SWITCH_BORDER = '000000' # Default = 000000 to be used with Checkbox Shape

SWITCH_DIMENSIONS = '40 20' # The ratio depends on the Shape. 0 = 40 20, 1 = 20 60, 2 = 60 120, 3 = 30 30

# batch_update_panel_parameters(PANEL_NAME, 'Switch', 'Shape', SWITCH_SHAPE)
# batch_update_panel_parameters(PANEL_NAME, 'Switch', 'Value (Off)', SWITCH_VALUE_OFF)
# batch_update_panel_parameters(PANEL_NAME, 'Switch', 'Value (On)', SWITCH_VALUE_ON)
# batch_update_panel_parameters(PANEL_NAME, 'Switch', 'Background (Off)', hex_to_rgba(SWITCH_BACKGROUND_OFF))
# batch_update_panel_parameters(PANEL_NAME, 'Switch', 'Background (On)', hex_to_rgba(SWITCH_BACKGROUND_ON))
# batch_update_panel_parameters(PANEL_NAME, 'Switch', 'Thumb', hex_to_rgba(SWITCH_THUMB))
# batch_update_panel_parameters(PANEL_NAME, 'Switch', 'Flip', hex_to_rgba(SWITCH_FLIP))
# batch_update_panel_parameters(PANEL_NAME, 'Switch', 'Base', hex_to_rgba(SWITCH_BASE))
# batch_update_panel_parameters(PANEL_NAME, 'Switch', 'Rocker', hex_to_rgba(SWITCH_ROCKER))
# batch_update_panel_parameters(PANEL_NAME, 'Switch', 'Background', hex_to_rgba(SWITCH_BACKGROUND))
# batch_update_panel_parameters(PANEL_NAME, 'Switch', 'Checkmark', hex_to_rgba(SWITCH_CHECKMARK))
# batch_update_panel_parameters(PANEL_NAME, 'Switch', 'Border', hex_to_rgba(SWITCH_BORDER))
# batch_update_panel_dimension(PANEL_NAME, 'Switch', SWITCH_DIMENSIONS)

# --- Button ---
# Uncomment needed batches

BUTTON_LATCH = '0'    # Non-latching = 0, Latching = 1
BUTTON_VALUE_IDLE = '0'  # Default = 0
BUTTON_VALUE_PRESSED = '1'  # Default = 1
BUTTON_CORNERS = '0'  # Round = 0, Square = 1
BUTTON_BORDER = '000000'  # Default = 000000
BUTTON_BACKGROUND_IDLE = 'ffffff'  # Default = ffffff
BUTTON_BACKGROUND_PRESSED = 'ffffff'  # Default = ffffff
BUTTON_LABEL_IDLE = 'Off'  # Default = Off
BUTTON_LABEL_PRESSED = 'On'  # Default = On
BUTTON_FONT_SIZE = '14'  # Default = 14
BUTTON_BOLD = '0'  # Default = 0
BUTTON_ITALIC = '0'  # Default = 0
BUTTON_UNDERLINE = '0'  # Default = 0
BUTTON_COLOR_IDLE = '000000'  # Default = 000000
BUTTON_COLOR_PRESSED = '000000'  # Default = 000000

BUTTON_DIMENSIONS = '80 30' # Default = 80 30

# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Latch', BUTTON_LATCH)
# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Value (idle)', BUTTON_VALUE_IDLE)
# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Value (pressed)', BUTTON_VALUE_PRESSED)
# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Corners', BUTTON_CORNERS)
# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Border', hex_to_rgba(BUTTON_BORDER))
# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Background (idle)', hex_to_rgba(BUTTON_BACKGROUND_IDLE))
# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Background (pressed)', hex_to_rgba(BUTTON_BACKGROUND_PRESSED))
# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Label (idle)', BUTTON_LABEL_IDLE)
# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Label (pressed)', BUTTON_LABEL_PRESSED)
# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Font size', BUTTON_FONT_SIZE)
# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Bold', BUTTON_BOLD)
# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Italic', BUTTON_ITALIC)
# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Underline', BUTTON_UNDERLINE)
# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Color (idle)', hex_to_rgba(BUTTON_COLOR_IDLE))
# batch_update_panel_parameters(PANEL_NAME, 'Button', 'Color (pressed)', hex_to_rgba(BUTTON_COLOR_PRESSED))
# batch_update_panel_dimension(PANEL_NAME, 'Button', BUTTON_DIMENSIONS)


# --- Dropdown ---
# Uncomment needed batches

DROPDOWN_BOLD = '0'  # Default = 0
DROPDOWN_ITALIC = '0'  # Default = 0
DROPDOWN_TEXT = '1d90ff'  # Default = 1d90ff
DROPDOWN_BACKGROUND = 'ffffff'  # Default = ffffff
DROPDOWN_BORDER = '000000'  # Default = 000000
DROPDOWN_DIMENSIONS = '150 20'  # Default = '100 30'

# batch_update_panel_parameters(PANEL_NAME, 'Dropdown', 'Bold', DROPDOWN_BOLD)
# batch_update_panel_parameters(PANEL_NAME, 'Dropdown', 'Italic', DROPDOWN_ITALIC)
# batch_update_panel_parameters(PANEL_NAME, 'Dropdown', 'Text', hex_to_rgba(DROPDOWN_TEXT))
# batch_update_panel_parameters(PANEL_NAME, 'Dropdown', 'Background', hex_to_rgba(DROPDOWN_BACKGROUND))
# batch_update_panel_parameters(PANEL_NAME, 'Dropdown', 'Border', hex_to_rgba(DROPDOWN_BORDER))
# batch_update_panel_dimension(PANEL_NAME, 'Dropdown', DROPDOWN_DIMENSIONS)


# --- Numeric Display ---
# Uncomment needed batches

NUM_DISPLAY_BOLD = '1'  # Default = 0
NUM_DISPLAY_ITALIC = '1'  # Default = 0
NUM_DISPLAY_TEXT = '000000'  # Default = 000000
NUM_DISPLAY_BACKGROUND = 'ffffff'  # Default = ffffff
NUM_DISPLAY_BORDER = '000000'  # Default = 000000
NUM_DISPLAY_FORMATTING = '0'  # Default = '0'
NUM_DISPLAY_DIMENSIONS = '100 20'  # Default = '100 20'
 
# batch_update_panel_parameters(PANEL_NAME, 'Numeric Display', 'Bold', NUM_DISPLAY_BOLD)
# batch_update_panel_parameters(PANEL_NAME, 'Numeric Display', 'Italic', NUM_DISPLAY_ITALIC)
# batch_update_panel_parameters(PANEL_NAME, 'Numeric Display', 'Text', hex_to_rgba(NUM_DISPLAY_TEXT))
# batch_update_panel_parameters(PANEL_NAME, 'Numeric Display', 'Background', hex_to_rgba(NUM_DISPLAY_BACKGROUND))
# batch_update_panel_parameters(PANEL_NAME, 'Numeric Display', 'Border', hex_to_rgba(NUM_DISPLAY_BORDER))
# batch_update_panel_parameters(PANEL_NAME, 'Numeric Display', 'Formatting', NUM_DISPLAY_FORMATTING)
# batch_update_panel_dimension(PANEL_NAME, 'Numeric Display', NUM_DISPLAY_DIMENSIONS)


# --- Gauge ---
# Uncomment needed batches

GAUGE_MINIMUM = '0'  # Default = 0
GAUGE_MAXIMUM = '10'  # Default = 10
GAUGE_DISPLAY = '1'  # Visible = 1, Hidden = 0
GAUGE_SCALE = '000000'  # Default = 000000
GAUGE_BACKGROUND = 'ffffff'  # Default = ffffff
GAUGE_NEEDLE = 'FF0000'  # Default = FF0000
GAUGE_LOWER_AREA = 'ffffff'  # Default = ffffff
GAUGE_LOWER_LIMIT = '1'  # Default = 0
GAUGE_UPPER_AREA = 'ffffff'  # Default = ffffff
GAUGE_UPPER_LIMIT = '5'  # Default = 5
GAUGE_FORMATTING = '0'  # Default = '0'
GAUGE_DIMENSIONS = '80 80'  # Default = '80 80' and should be equal to be Square
 
# batch_update_panel_parameters(PANEL_NAME, 'Gauge', 'Minimum', GAUGE_MINIMUM)
# batch_update_panel_parameters(PANEL_NAME, 'Gauge', 'Maximum', GAUGE_MAXIMUM)
# batch_update_panel_parameters(PANEL_NAME, 'Gauge', 'Display', GAUGE_DISPLAY)
# batch_update_panel_parameters(PANEL_NAME, 'Gauge', 'Scale', hex_to_rgba(GAUGE_SCALE))
# batch_update_panel_parameters(PANEL_NAME, 'Gauge', 'Background', hex_to_rgba(GAUGE_BACKGROUND))
# batch_update_panel_parameters(PANEL_NAME, 'Gauge', 'Needle', hex_to_rgba(GAUGE_NEEDLE))
# batch_update_panel_parameters(PANEL_NAME, 'Gauge', 'Lower area', hex_to_rgba(GAUGE_LOWER_AREA))
# batch_update_panel_parameters(PANEL_NAME, 'Gauge', 'Lower limit', GAUGE_LOWER_LIMIT)
# batch_update_panel_parameters(PANEL_NAME, 'Gauge', 'Upper area', hex_to_rgba(GAUGE_UPPER_AREA))
# batch_update_panel_parameters(PANEL_NAME, 'Gauge', 'Upper limit', GAUGE_UPPER_LIMIT)
# batch_update_panel_parameters(PANEL_NAME, 'Gauge', 'Formatting', GAUGE_FORMATTING)
# batch_update_panel_dimension(PANEL_NAME, 'Gauge', GAUGE_DIMENSIONS)


# --- Thermometer ---
# Uncomment needed batches

THERMOMETER_MINIMUM = '0'  # Default = 0
THERMOMETER_MAXIMUM = '10'  # Default = 10
THERMOMETER_DISPLAY = '1'  # Visible = 1, Hidden = 0
THERMOMETER_CORNERS = '0'  # Round = 0, Square = 1
THERMOMETER_BACKGROUND = 'F0F0F0'  # Default = F0F0F0
THERMOMETER_FILL = 'b3b3b3'  # Default = b3b3b3
THERMOMETER_GRADIENT = '0'  # Disable gradient = 0, enable gradient = 1
THERMOMETER_FILL_GRADIENT = '00ff00'  # Default = 00ff00
THERMOMETER_FORMATTING = '1'  # Default = '1'
THERMOMETER_DIMENSIONS = '20 240'  # Default = '20 240'
 
# batch_update_panel_parameters(PANEL_NAME, 'Thermometer', 'Minimum', THERMOMETER_MINIMUM)
# batch_update_panel_parameters(PANEL_NAME, 'Thermometer', 'Maximum', THERMOMETER_MAXIMUM)
# batch_update_panel_parameters(PANEL_NAME, 'Thermometer', 'Display', THERMOMETER_DISPLAY)
# batch_update_panel_parameters(PANEL_NAME, 'Thermometer', 'Corners', THERMOMETER_CORNERS)
# batch_update_panel_parameters(PANEL_NAME, 'Thermometer', 'Background', hex_to_rgba(THERMOMETER_BACKGROUND))
# batch_update_panel_parameters(PANEL_NAME, 'Thermometer', 'Fill', hex_to_rgba(THERMOMETER_FILL))
# batch_update_panel_parameters(PANEL_NAME, 'Thermometer', 'Gradient', THERMOMETER_GRADIENT)
# batch_update_panel_parameters(PANEL_NAME, 'Thermometer', 'Fill gradient', hex_to_rgba(THERMOMETER_FILL_GRADIENT))
# batch_update_panel_parameters(PANEL_NAME, 'Thermometer', 'Formatting', THERMOMETER_FORMATTING)
# batch_update_panel_dimension(PANEL_NAME, 'Thermometer', THERMOMETER_DIMENSIONS)


# --- LED ---
# Uncomment needed batches

LED_SHAPE = '0'  # Round = 0, Square = 1
LED_BACKGROUND_OFF = 'cccccc'  # Default = cccccc
LED_BACKGROUND_ON = '00FF00'  # Default = 00FF00
LED_DIMENSIONS = '20 20'  # Default = '20 20' and should be equal to be squared
 
# batch_update_panel_parameters(PANEL_NAME, 'LED', 'Shape', LED_SHAPE)
# batch_update_panel_parameters(PANEL_NAME, 'LED', 'Background (Off)', hex_to_rgba(LED_BACKGROUND_OFF))
# batch_update_panel_parameters(PANEL_NAME, 'LED', 'Background (On)', hex_to_rgba(LED_BACKGROUND_ON))
# batch_update_panel_dimension(PANEL_NAME, 'LED', LED_DIMENSIONS)


# --- Graph ---
# Uncomment needed batches

GRAPH_PERIOD = '1'  # Default = 1
GRAPH_SCALE_MODE = '1'  # Absolute = 1, Relative = 1
GRAPH_AUTOSCALE_Y = '0'  # Default = 0
GRAPH_MAX_Y = '100'  # Default = 100
GRAPH_MIN_Y = '-100'  # Default = -100
GRAPH_TRIG_CONDITION = '0'  # Rising Edge = 0, Falling Edge = 1, Above Level = 2, Below Level = 3
GRAPH_TRIG_LEVEL = '0'  # Default = 0
GRAPH_TRIG_X_POSITION = '0'  # Default = 0
GRAPH_TRIG_SHOW_ON_GRAPH = '0'  # Visible = 1, Hidden = 0
GRAPH_SHOW_LEGEND = '1'  # Visible = 1, Hidden = 0
GRAPH_BACKGROUND = 'ffffff'  # Default = ffffff
GRAPH_BORDER = '000000'  # Default = 000000
GRAPH_LABEL_X = 'Time'  # Default = Time
GRAPH_LABEL_Y = 'Amplitude'  # Default = Amplitude
GRAPH_DIMENSIONS = '340 320'  # Default = '320 340'
 
# batch_update_panel_parameters(PANEL_NAME, 'Graph', 'Period', GRAPH_PERIOD)
# batch_update_panel_parameters(PANEL_NAME, 'Graph', 'Scale mode', GRAPH_SCALE_MODE)
# batch_update_panel_parameters(PANEL_NAME, 'Graph', 'Autoscale (Y)', GRAPH_AUTOSCALE_Y)
# batch_update_panel_parameters(PANEL_NAME, 'Graph', 'Maximum (Y)', GRAPH_MAX_Y)
# batch_update_panel_parameters(PANEL_NAME, 'Graph', 'Minimum (Y)', GRAPH_MIN_Y)
# batch_update_panel_parameters(PANEL_NAME, 'Graph', 'Condition', GRAPH_TRIG_CONDITION)
# batch_update_panel_parameters(PANEL_NAME, 'Graph', 'Level', GRAPH_TRIG_LEVEL)
# batch_update_panel_parameters(PANEL_NAME, 'Graph', 'X position', GRAPH_TRIG_X_POSITION)
# batch_update_panel_parameters(PANEL_NAME, 'Graph', 'Show on graph', GRAPH_TRIG_SHOW_ON_GRAPH)
# batch_update_panel_parameters(PANEL_NAME, 'Graph', 'Show legend', GRAPH_SHOW_LEGEND)
# batch_update_panel_parameters(PANEL_NAME, 'Graph', 'Background', hex_to_rgba(GRAPH_BACKGROUND))
# batch_update_panel_parameters(PANEL_NAME, 'Graph', 'Border', hex_to_rgba(GRAPH_BORDER))
# batch_update_panel_parameters(PANEL_NAME, 'Graph', 'Label (X)', GRAPH_LABEL_X)
# batch_update_panel_parameters(PANEL_NAME, 'Graph', 'Label (Y)', GRAPH_LABEL_Y)
# batch_update_panel_dimension(PANEL_NAME, 'Graph', GRAPH_DIMENSIONS)


# --- Text ---
# Uncomment needed batches

TEXT_FONT_SIZE = '14'  # Default = 14
TEXT_ALIGN_H = '0'  # 0 = Left, 1 = Center, 2 = Right
TEXT_ALIGN_V = '0'  # 0 = Top, 1 = Middle, 2 = Bottom
TEXT_BOLD = '0'  # Default = 0
TEXT_ITALIC = '0'  # Default = 0
TEXT_UNDERLINE = '0'  # Default = 0
TEXT_COLOR = '000000'  # Default = 000000
TEXT_BACKGROUND = 'ffffff'  # Default = ffffff
TEXT_BORDER = '000000'  # Default = 000000
TEXT_DIMENSIONS = '40 80'  # Default = '40 80'
 
# batch_update_panel_parameters(PANEL_NAME, 'Text', 'Font size', TEXT_FONT_SIZE)
# batch_update_panel_parameters(PANEL_NAME, 'Text', 'Align H', TEXT_ALIGN_H)
# batch_update_panel_parameters(PANEL_NAME, 'Text', 'Align V', TEXT_ALIGN_V)
# batch_update_panel_parameters(PANEL_NAME, 'Text', 'Bold', TEXT_BOLD)
# batch_update_panel_parameters(PANEL_NAME, 'Text', 'Italic', TEXT_ITALIC)
# batch_update_panel_parameters(PANEL_NAME, 'Text', 'Underline', TEXT_UNDERLINE)
# batch_update_panel_parameters(PANEL_NAME, 'Text', 'Text color', hex_to_rgba(TEXT_COLOR))
# batch_update_panel_parameters(PANEL_NAME, 'Text', 'Background', hex_to_rgba(TEXT_BACKGROUND))
# batch_update_panel_parameters(PANEL_NAME, 'Text', 'Border', hex_to_rgba(TEXT_BORDER))
# batch_update_panel_dimension(PANEL_NAME, 'Text', TEXT_DIMENSIONS)
```

{% endcode %}

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/hypersim/automation-api-and-scripting/python-dashboard-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
