Display a blockly script as blocks

258 views
Skip to first unread message

olfa chibani

unread,
Mar 28, 2024, 8:34:26 AM3/28/24
to Blockly
I am reaching out to seek assistance regarding a project I have been working on involving Blockly. Specifically, my goal is to transform the Blockly xml script into a visually comprehensible format using Blockly.                                                                                              Could you please provide guidance on how to achieve this? Any help or explanations you could offer would be greatly appreciated.

Mark Friedman

unread,
Mar 28, 2024, 2:56:04 PM3/28/24
to blo...@googlegroups.com
Olfa,

  Can you provide some more details on what exactly you mean by the "Blockly XML script" and what you mean by a "visually comprehensible format"?

  I ask because there already exists an XML serialization format for Blockly workspaces (though it has been somewhat deprecated in favor of a JSON format).  For that XML, Blockly itself would be considered a visually comprehensible format. I.e., you could just use something like the following to have Blockly display the XML text visually as Blockly blocks:

Blockly.Xml.domToWorkspace(Blockly.utils.xml.textToDom(xmlText), workspace);

-Mark

On Thu, Mar 28, 2024 at 5:34 AM olfa chibani <olfach...@gmail.com> wrote:
I am reaching out to seek assistance regarding a project I have been working on involving Blockly. Specifically, my goal is to transform the Blockly xml script into a visually comprehensible format using Blockly.                                                                                              Could you please provide guidance on how to achieve this? Any help or explanations you could offer would be greatly appreciated.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/0e54b6d0-b485-431a-b4d0-3187b57251a0n%40googlegroups.com.

olfa chibani

unread,
Apr 1, 2024, 9:11:43 AM4/1/24
to blo...@googlegroups.com
Hello Mark,

Firstly, I want to express my gratitude for your support and the time you've dedicated to helping me.

Thes issue is that i have two custom Blockly scripts in XML format that simulate a user's experience visiting a website. My objective is to compare these scripts by visually comparing their results as blocks, in order to better understand the differences.
Therefore, I aim to transition from the code view to the block view. While I don't have much knowledge about Blockly serialization at the moment, I'm willing to explore it to see if it fits my needs.
Thank you once again for your assistance.

Cordially,






Mailtrack Sender notified by
Mailtrack
01/04/24 14:11:09

Beka Westberg

unread,
Apr 1, 2024, 12:23:26 PM4/1/24
to Blockly
Hello,

So do you already have the XML and you're looking to convert that into blocks? If that's the case, it might be easier to find a library that can highlight tree diffs. But I'm interested to hear more about your use-case!

Best wishes,
--Beka

Mark Friedman

unread,
Apr 1, 2024, 3:01:47 PM4/1/24
to blo...@googlegroups.com
Hi, Olfa.

  It's still not entirely clear to me what you mean by "Blockly scripts in XML format".  You say that you "aim to transition from the code view to the block view", but the standard Blockly XML serialization format, that I described in my earlier reply, isn't really code in the usual sense - it's a way to represent a set of Blockly blocks. So, I am wondering if your "Blockly scripts" are something else.  Can you explain what, exactly, your "Blockly scripts" are (and where they come from) and provide an example of such a script?

-Mark


olfa chibani

unread,
Apr 2, 2024, 6:42:51 AM4/2/24
to blo...@googlegroups.com
Hello Mark, I am extremely grateful for your guidance.  Let me provide further details about my use case: 
The idea is to test bugs in an application (web, mobile, etc.). For this purpose, for each scenario (for example: the steps to log in), they have designed blocks in Blockly corresponding to each user experience, along with its corresponding XML block result, and that's what I have for each scenario. I want to reverse this process and display this script in block format to analyze and understand it.  
Unfortunately, I'm unable to provide any examples due to confidentiality reasons. Nonetheless, I truly value your guidance.

Best regards, Olfa.






Mailtrack Sender notified by
Mailtrack
02/04/24 11:41:36

olfa chibani

unread,
Apr 2, 2024, 7:50:26 AM4/2/24
to blo...@googlegroups.com
I wanted to inform you that I have attempted the method you mentioned about blockly serialisation : 
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xmlText, "text/xml");

// Clear existing blocks from workspace
workspace.clear();

// Load blocks from XML into workspace
Blockly.Xml.domToWorkspace(xmlDoc.documentElement, workspace);

I then loaded the code into an HTML file to open it in a web browser. However, I encountered an error stating "invalid block!" It appears that the Blockly script I have contains custom blocks that need to be defined in JavaScript ! 

Is there any solution to address this issue?
Looking forward to your guidance.


Olfa. 






Mailtrack Sender notified by
Mailtrack
02/04/24 12:48:58

Beka Westberg

unread,
Apr 2, 2024, 11:32:29 AM4/2/24
to blo...@googlegroups.com
Hello Olfa,

Could you post the full text of the error? I'm still a bit confused about whether you have defined the blocks (e.g. "they have designed blocks in Blockly corresponding to each user experience") or not. Do you have somewhere with block definitions like these?

Best wishes,
--Beka

olfa chibani

unread,
Apr 2, 2024, 8:00:33 PM4/2/24
to blo...@googlegroups.com
Hello Beka, 

I'm reaching out regarding the recent issue encountered with the JavaScript Blockly script. Upon investigation, I discovered that there seems to be an error related to the usage of customized blocks within the XML script.
The error message received is as follows:
Uncaught TypeError: Invalid block definition for type: main_block
    at new Block$$module$build$src$core$block (javascript.ts:32:14)
    at new BlockSvg$$module$build$src$core$block_svg (javascript.ts:32:14)
    at WorkspaceSvg$$module$build$src$core$workspace_svg.newBlock (javascript.ts:32:14)
    at domToBlockHeadless$$module$build$src$core$xml (math.ts:335:9)
    at domToBlockInternal$$module$build$src$core$xml (math.ts:297:9)
    at $.domToWorkspace$$module$build$src$core$xml [as domToWorkspace] (math.ts:297:9)
    at myscr.html:79:17   
It appears that the 'main_block' type within the XML script is causing this issue.
As per your query, I do not have a block definition in JavaScript; rather, I have access to a Blockly script in JSON/XML format. Indeed, I did not structure the blocks in Blockly myself to obtain the corresponding JSON/XML script. I only have the resulting JSON script from blocks assembly.

Olfa, 







Mailtrack Sender notified by
Mailtrack
03/04/24 00:59:20

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/CAAojf0xPJOSZyVnbbFm4kZRoiMC2dax1f%3DK1-kbzbNwK9ObMEQ%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.

Beka Westberg

unread,
Apr 3, 2024, 12:50:38 PM4/3/24
to blo...@googlegroups.com
Hello,

It sounds like you need to define some custom blocks. If you don't define your blocks, Blockly doesn't know what to create from the XML.

Best wishes,
--Beka

olfa chibani

unread,
Apr 4, 2024, 7:57:14 AM4/4/24
to blo...@googlegroups.com
Hello, Unfortun



Mailtrack Sender notified by
Mailtrack
04/04/24 12:55:36

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/CAAojf0xjUpWBcj%3DazExc7g3wssitEhGu4cLUehmqBfv1fko%3D6Q%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.

olfa chibani

unread,
Apr 4, 2024, 8:04:48 AM4/4/24
to blo...@googlegroups.com
Hello Beka, 
Unfortunately, I haven't found a solution to have the Blockly blocks visualized from xml script. Considering that block definition takes a lot of time, and I have many script examples that I want to visualize.
Cordially, 
Olfa.




Mailtrack Sender notified by
Mailtrack
04/04/24 13:04:24

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/CAAojf0xjUpWBcj%3DazExc7g3wssitEhGu4cLUehmqBfv1fko%3D6Q%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.

Mark Friedman

unread,
Apr 4, 2024, 11:50:26 AM4/4/24
to blo...@googlegroups.com
Olfa,

  Can you describe in some more detail what your overall system is?  While not impossible, it would be quite unusual to produce Blockly-formatted XML files from a process that does not include Blockly (i.e. that does not use Blockly serialization functions).  Assuming that these XML files were produced by Blockly, then the application that is producing the XML files would have the block definitions that you need to do your visualizations.  Do you not have access to the application that is producing the XML files?

-Mark


Reply all
Reply to author
Forward
0 new messages