Blocks to text

In years past, you could create code with blocks in Graphical RobotC. When it was finished, there was an option to convert the blocks to text. I loved this for my students as it helped them to see what the actual text looked like for a blocks program they created. Bridging the gap so to speak.

I would like to see this option as well in IQBlocks and V5Blocks. It’s possible that it is there, but I’m not finding it. If it is not - VEX, could you pretty please add that option in for VEXCode?


1 Like

I believe this exact request is supported using Robot Mesh Studio. You can convert directly from Blockly to python.

Would RMS be able to open a VEXCode file?

Unfortunately not.

Didn’t think so. Don’t want to have students create the same program twice. :expressionless:

Thus the request to add to VEXCode.

Already planned for later this year with VEXcode IQ/V5 Text updates. We’re working to clean up the V5 SDK a bit to make the transition between the two more seamless.


Super news! Thanks.

Btw, happy anniversary! :cake:

1 Like

If you are comfortable with some command line and manual work, I am pretty sure you can port the code yourself.

In my test, I made a VEXCode V5 Blocks project called helloWorld. I added one line of code that prints “Hello World” to the brain’s screen. The file VEX Blocks saves is called helloWorld.v5blocks. This file is in JSON format. There’s a key in the file named ‘cpp’ whose value is all of the C++ code the Blocks program created for my “Hello World” program.

That C++ code has been reformatted so it can be stored on a key in a JSON file. On one level this makes it unreadable, but with the right filters you can convert it back into readable C++. I used the jq command and perl to do the job. jq will read the value of any JSON key I name. I used perl to replace the “\n” characters with newlines. With piping, the magic looks like this:

cat helloWorld.v5blocks | jq -r '. | .cpp' | perl -pe "s/\\\n/\n/g;"  > helloWorld.cpp

The output file is helloWorld.cpp. It is a single, compilable C++ file. If you make an analogous HelloWorld project in VEXCode V5 Text, you’ll find the content is very similar, but the layout is different. The layout of a VEXCode V5 Text project is fairly typical of normal C++ coding style whereas the code extracted from the v5blocks file is one monolith.

My theory is that one could cut and paste the relevant parts of a v5blocks code extract into a new VEXCode V5 Text project. I haven’t tested this yet. It’s up to the team I am mentoring to try it. My hope is this will give them a reasonably easy path off VEXCode V5 Blocks. They are bumping up against its limits and can’t use the advice they are getting from the other teams who are already working in C++.

See and for the filters I used.


I have an update from this past Thursday: the port from blocks to text works. It was easier than I imagined. :smiley:

Robot club was Thursday and I had a chance to meet with the developer. I told her about the research I did and how I thought it would let her switch to V5 text. She wanted to try it, so we fed her .v5blocks file into the filter. I opened the result in a text editor for her to look at. She immediately recognized variables she had named. A little bit of the code in the .cpp files was framework written by v5Blocks, but the vast majority was code she recognized as her own.

The code V5Blocks wrote involved include files, initialization code, naming of subsystem functions, and subsystem task management. I explained these parts of the code to the developer. The task start-stop code neede a little reformatting , but the code was otherwise well-formatted and readable straight out of the filter.

I explained to the developer what refactoring meant and how that was what we were doing. I explained how the smart move was to make no changes that are not absolutely necessary to get the code to build, download and run in V5 Text. She was OK with that so we started the real work of cutting and pasting the exported V5 Blocks code into an empty V5 Text project.

The exported V5Blocks file is one large .cpp file. The V5 text file is two .h files and two .cpp files. To do the port we copied code into the V5 text main.cpp. We ignored all of the include statements in the source file. We copied all of the initialization code and every function definition from the source file except for main(). To address the important parts of the main, we copied all the lines within main() from the source file and pasted them into the target file’s main.h below the vexcodeInit(); line. When the cut-and-paste work was done, the V5Text showed no parsing errors–the red squiggly lines.

The ported code built, downloaded and worked on the first try. In their testing, the team found one bug: the text they were writing to the brain’s screen was not formatted correctly. It was a minor bug. Before I left that day the developer was already modifying the Text code and sending revisions to the 'bot.

The entire session with the developer took 2 hours, but this was mostly a conversation about refactoring code, function naming conventions, and task management. The technical work was about 20 minutes of reading code and cut-and-paste. It was a good experience.

Many thanks to @sankeydd for the tip that the CPP code was embedded in the .v5blocks files. That was the critical info I needed to make this happen.


This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.