Coding Reference
This page explains how to write Custom Blocks for AugeLab Studio Designer.
Custom Blocks are plain Python classes that subclass Block, define sockets/components in init(), and process data in run().
Quick Start
Start your script with
from studio.custom_block import *(mandatory).Create a class that subclasses
Block.Set
op_codeto the exact class name.Implement
init()to configure sockets and UI components.Implement
run()to read inputs and write outputs.Register the block at the bottom with
add_block(...).
from studio.custom_block import *
try:
import numpy as np
except ImportError:
np = None
class Example_Block(Block):
op_code = "Example_Block" # Must match the class name
def init(self) -> None:
self.width = 200
self.height = 150
self.tooltip = "Adds a constant to the input image."
# Socket names become keys for self.input[...] and self.output[...]
self.input_sockets = [SocketTypes.ImageAny("Input Image")]
self.output_sockets = [SocketTypes.ImageAny("Output Image")]
# Components are stored by name in self.param
self.param["Increment"] = TextInput(
text="1",
place_holder="integer",
tool_tip="Value added to every pixel.",
)
def run(self) -> None:
if np is None:
return
img = self.input["Input Image"].data
inc = int(self.param["Increment"].value)
self.output["Output Image"].data = img + inc
add_block(Example_Block.op_code, Example_Block)
Bootstrap Phase
Mandatory Imports
Every Custom Block script must begin with from studio.custom_block import *.
It provides Block, SocketTypes, Designer components (TextInput, Slider, β¦), and add_block.
Importing Community Modules
You may import third-party packages (NumPy, OpenCV, β¦) and use them inside run().
If you install packages via the Import Package Window, make sure they work on all target platforms where your scenario will run.
All blocks shipped with AugeLab Studio are cross-platform compatible. Installing or importing community modules may reduce portability.
Class Definition
The class name becomes the block name shown in the Custom Blocks list.
You can add helper methods and internal state as needed.
Core Attributes & Methods
Block.op_code: str
Block.op_code: strUnique identifier for your block.
For Designer-generated blocks, op_code should be the same as the class name.
Block.tooltip: str
Block.tooltip: strTooltip text shown when the user hovers over the block.

Block.init(self) -> None
Block.init(self) -> NoneCalled when the block is created (drag-drop), duplicated (copy/paste), or loaded from a scenario file.
Use this method to configure the block UI and sockets:
Define
input_socketsandoutput_socketsCreate components in
self.param(TextInput, DropDown, Slider, ...)Load and register resource paths if needed
Block.run(self) -> None
Block.run(self) -> NoneExecuted on every scenario step.
Read from self.input, write to self.output, and (optionally) update component state.
Sockets & Data Flow
Block.input_sockets: list[SocketType]
Block.input_sockets: list[SocketType]Defines which inputs the block accepts.
Each socket has a visible name; that same name becomes the key you use in self.input[...].
Block.output_sockets: list[SocketType]
Block.output_sockets: list[SocketType]Same concept as inputs: define outputs and then write data by socket name using self.output["Name"].data = ....
Block.input: dict[str, object]
Block.input: dict[str, object]Runtime map of input socket names to objects that carry the payload in .data.
Each input also tracks connection state in .is_connected. If an input is not connected, .data is set to None.
Block.output: dict[str, object]
Block.output: dict[str, object]Runtime map of output socket names to objects that carry the payload in .data.
Components (Block UI)
Block.param: dict[str, Component]
Block.param: dict[str, Component]Components are stored in self.param by a unique name you choose.
Use them to configure your block UI (text fields, sliders, buttons, images, tables, etc.).
Resource Paths
Block.register_resource(name: str = "", path: str = "") -> str
Block.register_resource(name: str = "", path: str = "") -> strRegisters a file/folder path so it is stored with the scenario and can be relocated with the project. This avoids hard-coded absolute paths breaking when a scenario is moved to another computer.
name
Unique identifier for the resource
path
File/folder path to register
Returns: str (the registered path)
To retrieve the stored path later, use get_resource().
Block.get_resource(name: str = "") -> str
Block.get_resource(name: str = "") -> strReturns the registered path for a given resource name.
File Dialogs
QAFileDialog
QAFileDialogStatic helper for showing file/folder pickers. These dialogs return a path chosen by the user.
QAFileDialog.getOpenFileName(**kwargs)
QAFileDialog.getOpenFileName(**kwargs)caption: str = ""
Dialog title
directory: str = ""
Start directory
filter: str = ""
File filter, e.g. "Image Files (*.png *.jpg *.bmp)"
Returns: str (selected file path)
QAFileDialog.getExistingDirectory(**kwargs)
QAFileDialog.getExistingDirectory(**kwargs)caption: str = ""
Dialog title
directory: str = ""
Start directory
Returns: str (selected directory path)
Registration
add_block(My_Block.op_code, My_Block)
add_block(My_Block.op_code, My_Block)Registers your block so it appears in the Designer. This is typically generated for you by the Designer Window. If you modify it, keep op_code and the class name consistent.
Last updated
Was this helpful?