blocklypy
v0.0.39
Published
Blocklypy: SPIKE to Pybricks - word-block converter to Pybricks python code
Downloads
846
Readme
BlocklyPy
LEGO SPIKE and Mindstorms Code to Pybricks - block-code converter to Pybricks python code
This library will convert the LEGO standard graphical blockly files to Pybricks python files.
SPIKE Prime (45678) and SPIKE Essentials (45345) kit and Robot Inventor (51515) kit for word-blocks and icon-blocks transformation.
- SPIKE v2 (.llsp) files.
- SPIKE v3 (.llsp3) files.
- Robot Inventor files (.lms).
EV3 Mindstorms kit (31313) LabView EV3-G code transformation:
- EV3Classroom files (.lmsp).
- EV3 Lab (.ev3) files.
- EV3 Lab Compiled Binary (.rbf) files.
Usage
const { convertProjectToPython } = require('blocklypy');
const file = fs.readFileSync(__FILE__);
const options = { filename: 'sample.llsp3' };
convertProjectToPython(file, options).then((retval) => {
console.log(retval.pycode);
});
Result
Type: PyProjectResult
pycode
Type: string
Python representation of the blockly code in Pybricks flavour.
"""
Project: test1
Slot: 0
Created: 2024-09-02T09:08:14.079Z
Last saved: 2024-09-03T16:57:06.369Z
"""
#region ========================== SECTION: IMPORTS ========================== #
from pybricks.hubs import PrimeHub
from pybricks.tools import wait
#endregion
...
#region ======================= SECTION: PROGRAM CODE ======================== #
# ------------------------------- GROUP: START ------------------------------- #
# STACK #1: flipperevents_whenProgramStarts()
def stack1_whenprogramstarts_fn():
hub.display.pixel(0, 0, 100)
hub.display.icon(convert_icon_matrix("9909999099000009000909990", g_pixel_brightness))
wait(convert_time(g_aa))
hub.display.off()
#endregion
#region ====================== SECTION: MAIN CODE ============================ #
stack1_whenprogramstarts_fn()
#endregion
plaincode
Type: string
Pseudo code of the blockly code.
flipperevents_whenProgramStarts()
flipperlight_lightDisplaySetPixel(x: "1", y: "1", brightness: 100)
flipperlight_lightDisplayImageOnForTime(matrix: "9909999099000009000909990", value: g_aa)
flippermove_movementSpeed(speed: 50)
flippermove_startMove(direction: "back")
data_setvariableto(value: "0", variable: "aa")
data_changevariableby(value: 13, variable: "aa")
flipperlight_lightDisplayImageOn(matrix: "9909999099000009000909990")
additionalFields
blockly.slot
Type: number
Project slot information of the specified program.
blockly.svg
Type: string
SVG snapshot of the canvas.
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 628 223"><g xmlns="http://www.w3.org/2000/svg" class="blocklyWorkspace" transform="translate(-402.1000061035156,-144.5)"><g class="blocklyBlockCanvas" transform="translate(309.9999999999993,102.99999999999989) scale(0.675)"><g data-id=";KLd5R]$I`vV1#%|zmC(" class="blocklyDraggable" data-shapes="stack" data-category="flippermove" transform="translate(757.1851851851851,270.6666666666666)"><path class="blocklyPath blocklyBlockBackground" stroke="#B2248A" fill="#FF4CCD" fill-opacity="1" d="m 0,4 A 4,4 0 0,1 4,0 H 12 c 2,0 3,1 4,2 l 4,4 c 1,1 2,2 4,2 h 12 c 2,0 3,-1 4,-2 l 4,-4 c 1,-1 2,-2 4,-2 H 305.5812768936157 a 4,4 0 0,1 4,4 v 48 a 4,4 0 0,1 -4,4 H 48 c -2,0 -3,1 -4,2 l -4,4 c -1,1 -2,2 -4,2 h -12 c -2,0 -3,-1 -4,-2 l -4,-4 c -1,-1 -2,-2 -4,-2 H 4 a 4,4 0 0,1 -4,-4 z"/><g transform="translate(8, 12) "><use xlink:href="#23791e70ccbd66ad86ec73ee6ff26211e0bb5feb"/></g>
...