SPIKE to Pybricks - word-block converter to Pybricks python code
This library will convert the LEGO standard blockly files to Pybricks python files. Options include SPIKE v2/v3 (.llsp3, .llsp) and Robot Inventor files (.lms) with word-blocks and icon-blocks.
Experimentally added transforming EV3Classroom files (.lmsp) and old EV3 Lab EV3G (.ev3) files.
const { convertProjectToPython } = require('blocklypy');
const file = fs.readFileSync(__FILE__);
const options = { filename: 'sample.llsp3' };
convertProjectToPython(file, options).then((retval) => {
console.log(retval.pycode);
});
Type: PyProjectResult
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
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")
Type: number
Project slot information of the specified program.
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>
...