Convert Scratch project to Python

at first

The reason why I decided to do this is that when I switched from Scratch to Python, I thought "I wonder if I can change from Scratch to Python ..." and Python understood that, Unity and When doing C # "By the way, I wonder if there is a way to change from Scratch to Python ... Look for it." "No ..." "Say, I made it myself." I decided to make it.

One of them

Search for analysis target

First, you get the .sb3 file when you download the Scratch project file. If the sb3 file cannot be parsed, nothing can be done. So when I searched for "sb3 file analysis", I arrived at a site that displayed the names of variables used in the Scatch project. Change the extension to .zip and drag the site. So, I thought this might be the case, I changed the extension to .zip, and when I unzipped it, I found a json that looked suspicious. Looking at the contents of it, it clearly writes things such as blocks. For the time being, the file to be analyzed was found. projectj.png

Make a GUI

At that time, I wanted to distribute it, so I wanted to make it something that anyone could do. If you make it with PythonTkinter, only people who have python installed can execute it, so I made it into C # Form and made the GUI part. GUI.png

Zip unzip

I managed to use the ZipArchive (C #) class.

Part two

json parsing

Even if I tried to parse Json in C #, I had to create a class dedicated to it, so I reluctantly decided to use the Json module of Python. After doing such a thing and such a thing, Json's analysis was completed safely. By the way, I decided to use System.Diagnostics.Process to execute Python in order to execute it automatically.

writing

I thought I would write it in C #, but I decided to write it in python because I had done the Json parsing in python. However, I had to specify the location and name of the file to write to, so I decided to put an argument at runtime and read it with sys.argv. After that, open () and write () in the if hell at the time of Json analysis is OK.

Finally

Should this be distributed? I'm afraid I'll rely on this tool if I do. (Is there anyone who downloads it in the first place?) Not compatible with some blocks. This isn't a hassle, but if you want to do more than that, you can use Python.

Bonus: Troublesome place

Json parsing

The block definition of the json file is divided into one block. One operator is also one block. In other words, when calculating 5 + 5 + 5 + 5 + 5, I used a recursive function. But that's only close to 1000, so please let me know if you have a better idea.

writing

I've been using .format () for a long time because I didn't know the f string until it was almost completed. I thought it would be nice if there was something like a C # \ $ string, and when I googled it, there was an f string and it was f awesome. Maybe the f string or the \ $ string is different.

stack

After exiting the if or for block, I have to write else or the one below it, so I saved that else or the one below it in the list, and when I called it, it was the current layer -1. That guy

if True:
    if True:
        if True:
            if True:
                print("Hello")
    print("World")#-2 has been. You can use and

Because there was something like that, I decided to save the hierarchy at the time of if together.

Really at the end

I don't know why, but thank you for watching so far.

Postscript

~~ Published ~~. ~~https://www.axfc.net/u/4023085~~

Recommended Posts

Convert Scratch project to Python
[python] Convert date to string
Convert numpy int64 to python int
[Python] Convert list to Pandas [Pandas]
[Python] Convert Shift_JIS to UTF-8
Convert python 3.x code to python 2.x
Convert markdown to PDF in Python
Convert list to DataFrame with python
Python> list> Convert double list to single list
[Python] Convert natural numbers to ordinal numbers
Convert decimal numbers to n-ary numbers [python]
Python> tuple> Convert double tuple to single tuple
Updated to Python 2.7.9
Convert memo at once with Python 2to3
Convert to HSV
Convert Python> two value sequence to dictionary
[Python] How to convert a 2D list to a 1D list
How to convert Python to an exe file
[Python] Convert csv file delimiters to tab delimiters
Convert Hiragana to Romaji with Python (Beta)
Convert from katakana to vowel kana [python]
Convert FX 1-minute data to 5-minute data with Python
python> Convert tuple to list> aList = list (pi_tuple)
Convert Python date types to RFC822 format
Convert HEIC files to PNG files with Python
Convert Chinese numerals to Arabic numerals with Python
Convert from Markdown to HTML in Python
Convert absolute URLs to relative URLs in Python
"Backport" to python 2
Sample to convert image to Wavelet with Python
[Python] Introduce UIKit3 to your Django project
Convert FBX files to ASCII <-> BINARY in Python
Convert PDF to image (JPEG / PNG) with Python
Convert "number" of excel date to python datetime
Convert PDFs to images in bulk with Python
Python script to convert latitude / longitude to mesh code
[Python] Convert from DICOM to PNG or CSV
Convert svg file to png / ico with Python
Convert Windows epoch values to date with python
How to convert SVG to PDF and PNG [Python]
Convert STL to Voxel mesh using Python VTK
Convert exponential notation float to str in Python
Convert cubic mesh code to WKT in Python
Convert strings to character-by-character list format with python
How to install Python
Convert 202003 to 2020-03 with pandas
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
Convert kanji to kana
Rewrite Python2 code to Python3 (2to3)
Convert jupyter to py
How to install python
python decorator to retry
Introduction to Python language
Convert keras-yolo3 to onnx
Introduction to OpenCV (python)-(2)
Convert dict to array
Note to daemonize python
Introducing Python 2.7 to CentOS 6.6
Convert json to excel
Connect python to mysql