Skip to main content

Blocky Programming

Graphical programming is the core feature of Dobot+. By configuring to generate corresponding blocks, you can reduce the difficulty of script writing. Locate src/config/Blocks.json and customize the blocks you want by specifying parameters.

This chapter will introduce how to configure dynamically generated blocks, and you will learn about:

  • How to customize the appearance of blocks
  • How to configure block-to-code conversions
  • How to support multithreading
  • How to customize the menu bar icons
  • How to add pop-up pages for blocks
  • How to perform internationalization
  • How to debug blocks online

Customizing Blocks

We support executing blocks, returning value blocks, judging blocks, and ending blocks.

JSON Configuration

{
"block_name": "SetModbusIODigitOutput",
"block_color": "#4D7DDD",
"block_type": "shape_statement"
}

Description of Fields

FieldTypeDefault ValueRequiredDescription
block_namestringNoneYesThe name of the block function; only pure letters are supported.
block_colorhexadecimal color stringNoneYesThe color of the block.
block_typeBLOCK_TYPENoneYesThe shape of the block, indicating the logic used.

BLOCK_TYPE

TypeDescriptionStyle
shape_statementCode block with no output
output_numberCode block outputting numbers
output_stringCode block outputting strings
output_booleanCode block outputting booleans
shape_endCode block indicating the end of flow
shape_hatCode block indicating the start of flow

Note:

  • When configuring block_name, different blocks cannot repeat; repetition will lead to data overwriting.
  • It is recommended to use a uniform color for the same plugin.
  • Supports custom parameter types for blocks.

Custom Parameter Types JSON Configuration

[
{
"message": "设置扩展IO数字输出 %1 %2",
"params": [
{
"param_type": "field_dropdown",
"data_type": "",
"name": "name",
"default": "",
"options": [
{
"label": "Modbus_IO1",
"value": "default"
}
],
"update": {
"type": "lua",
"function": "GetModbusArr",
"args": {
"type": "custom",
"value": "do"
}
}
},
{
"param_type": "field_dropdown",
"data_type": "",
"name": "do",
"default": "",
"options": [
{
"label": "DO_101",
"value": "default"
}
],
"update": {
"type": "lua",
"function": "GetModbusDOArr",
"args": {
"type": "field",
"value": "name"
}
}
}
]
}
]

Description of Fields for Custom Parameters

FieldTypeDefault ValueRequiredDescription
messagestringNoneYesThe block uses %n for interpolation.
paramsParamsType[]NoneYesDefinition of block parameters.

ParamsType

FieldTypeDefault ValueRequiredDescription
param_typeInputTypeNoneYesThe type of the parameter.
data_typemath_number | textNoneNoThe data type.
namestringNoneNoName for the input field.
defaultstringNoneNoDefault value for the parameter.
options{label:string,value:string}[]NoneNoRequired when the parameter type is 'field_dropdown'; label is for display, value is the actual value for code conversion.
updateupdateTypeNoneNoHTTP interface call triggered when the block needs to be updated.

InputType

TypeDescription
input_valueInput box
field_dropdownDropdown box
input_statementNested statement

Block-to-Code Conversion

JSON Configuration for Code Conversion

{
"block_code": ["DO({do},{status})"]
}

Description of Fields

FieldTypeDefault ValueRequiredDescription
block_codestring[]NoneYesCode generated from the block.

Note:

  • shape_statement and shape_end type blocks must have a newline character /n added at the end of their code conversion.
  • For multithreaded blocks, parameters for code conversion should be in array format, sequentially converted into main thread code (src0.lua), child thread code (src1.lua), (src2.lua), etc.
  • Refer to Advanced Block Configuration to learn about complex block configuration methods, such as for welding scenarios.

Custom Menu Bar Icons

If you need to display custom icons for the menu bar block group, place the icon resources in Resources/images. Specify the icon's name in Blocks.json, and the icon information will be synchronized with the graphical interface after the plugin is installed.

JSON Configuration

{
"block_menuIcon": "grip.png"
}

Description of Fields

FieldTypeDefault ValueRequiredDescription
block_menuIconstringNoneNoThe menu bar icon path; defaults to the standard icon if not configured.

Block Pop-up Pages

Dobot+ blocks support pop-up pages for secondary processing in complex parameter scenarios. Clicking on a block displays a pop-up.

JSON Configuration

{
"block_page": "template.html"
}

Description of Fields

FieldTypeDefault ValueRequiredDescription
block_pagestringNoneNoIndicates whether the block has a configuration page; provide the static page path to display a clickable icon.

Internationalization

You can configure translations for blocks in the Resources/i18n/client folder.

  • In Resources/i18n/client/zh.json, add to the blocks field:

    {
    "blocks": {
    "tr_dobot_set_extio": "设置扩展IO数字输出 %1 %2"
    }
    }
  • In Resources/i18n/client/en.json, add to the blocks field:

    {
    "blocks": {
    "tr_dobot_set_extio": "Set extended IO digital output %1 %2"
    }
    }
  • Use the translation in the block:

    {
    "block_configs": [
    {
    "message": "%{tr_dobot_set_extio}"
    }
    ]
    }

Note:

  • The message configuration uses %n for interpolation placeholders, and the quantity must match the items in the params configuration; otherwise, the block will fail to load.
  • Use %1 for the first item in the params configuration, %2 for the second, and so on.

Online Debugging of Blocks

We support online debugging of block configuration parameters, allowing real-time previews of block effects. Execute the following command, and open the corresponding URL in a browser, then click on the block module.

dpt gui
  • Click on the block name in the left menu to view block configuration details.

  • Click the + button to create a new block.

  • After the plugin is successfully created, you can preview the block effect on the page.

  • Hover over the left block menu to see a delete button. Click the red delete button to remove any unnecessary blocks.