Coding Reference
Sample custom block script provided in AugeLab:
Bootstrap Phase
Mandatory Imports
Sample script always starts with imports of certain modules. from studio.custom_block import *
imports necessary super classes, widgets and methods for you to utilize in your block. This line is mandatory for all class definitions.
Importing Community Modules
Here, most used two libraries are already set to be imported for you. You can use OpenCV and numpy libraries in your custom blocks.
You can also import custom libraries by installing them with Import Package Window and set-read custom static variables.
All blocks provided in AugeLab Studio is cross platform compatible. However, using community modules may compromise that.
Class Definition
Name of your class is determined by whatever title you've provided in Block Name text edit. You can introduce attributes or methods however you like in this section.
Class Attributes-Methods
`Block.op_code: str`
op_code
defines a unique identifier string for your custom block. To upload your custom block, you must choose a unique block name for your custom block.
`Block.tooltip: str`
tooltip
allows you to show tooltips on your custom blocks when users hover over your custom block.
`Block.input_sockets: list[SocketType]`
input_sockets
attribute stores socket types. Each socket type is automatically generated for you in Input Socket or Output Socket section.
SocketType
takes two arguments:
List of SocketType
s can be seen below:
[
ImageAny
]: ImageRGB | ImageGray
[
ImageRGB
]: npt.NDArray[np.uint8] # [N, N, 3]
[
ImageGray
]: npt.NDArray[np.uint8] # [N, N]
[
Integer
]: int
[
Float
]: int
[
Number
]: float | int
[
Boolean
]: bool
[
String
]: str
[
Generic
]: object
[
Shape
]: list[list[int, int], ...]
[
Pixel
]: tuple[int] | tuple[int, int, int]
[
Point
]: tuple[int, int]
`Block.output_sockets: list[SocketType]`
Same rules on Input_sockets applies to this section as well.
`Block.param: dict[str, Component]`
This property holds your block components, and interactable widgets by their unique names. There are several components you can utilize:
`Block.input: dict[str, object]`
input
property is a dynamic dict
that transfer data into your custom block. You can retrieve data from your input sockets by their unique socket names.
`Block.output: dict[str, object]`
output
property is a dynamic dict
that transfer data out of your custom block. You can place data into your output sockets by their unique socket names.
`Block.register_resource(name: str = '', path: str = '') -> str`
Registers paths and automatically saves them in the scenario file.
Normally, using raw paths may create problems during transferring scenario files across different computers. However, using automatic resource management allows you to use generic or relative paths. Simply storing a resource in a path lower than the scenario file will allow your script to receive the correct path no matter the where the root path is.
Arguments:
name: str
: Unique name provided to distinguish a path.
path: str
: Path to be registered.
Returns:
path: str
: Registered path.
To receive the path provided, use get_resource
method.
`Block.get_resource(name: str = '') -> str`
Allows you the receive the resource you have provided into resource manager of a custom block.
Arguments:
name: str
: Unique name provided to distinguish a path.
Returns:
path: str
: Registered path.
To register a path, use register_resource
method.
`Block.init(self)`
This part is executed every time when a custom block is dragged-dropped, copy-pasted, or loaded in a new scenario. It's mostly advised to use this section to:
Load resources for your custom block
Define components to be used (text inputs, buttons etc.)
Inner block states that change with runtime.
`Block.run(self)`
Run method is executed at every step of an execution of a scenario in AugeLab Studio. You can utilize your custom blocks inner states, custom modules, constants etc.
You can receive inputs by utilizing dynamic attributes provided by super Block
class and send outputs as well, change configurations of your components and read component state to choose the right execution logic.
`QAFileDialog`
QAFileDialog is a static class that offers file path choosing dialog for users:
`QAFileDialog.getOpenFileName(**kwargs)`
Arguments
caption: str = ''
: Title of file dialog header
directory: str = ''
: Starting directory of the dialog
filter: str = ''
: Filenames to be filtered, for example -> 'Image Files (*.png *.jpg *.bmp)'
Returns
path:str
: Chosen path by user.
`QAFileDialog.getExistingDirectory`
Arguments
caption: str = ''
: Title of file dialog header
directory: str = ''
: Starting directory of the dialog
Returns
path:str
: Chosen path by user.
`add_block(My_Block.op_code, My_Block)`
This part is automatically generated by the Designer Window and should not be modified. If to be modified, make sure the block name is the same as class name and op_code.
Last updated