Arrange blocks from JS code

77 views
Skip to first unread message

Riya Patadiya

unread,
Jul 2, 2024, 11:19:55 AMJul 2
to Blockly
I am new to Blockly blocks. I request you to suggest me some ways to arrange blocks directly into canvas from JavaScript generated code earlier.

Beka Westberg

unread,
Jul 2, 2024, 11:30:14 AMJul 2
to blo...@googlegroups.com
Hello!

If you're asking how to go from code to blocks, we don't have any specific for doing that. It's hard to do generally because there are some JavaScript semantics (like assigning functions to variables) that Blockly doesn't have a way to visualize. Theoretically you could create a parser for a restricted set of JavaScript and use that to create your blocks.

If you just want to create blocks programmatically (not go from code to blocks), you can check out our serialization docs.

I hope that helps! If you have any further questions please reply =)
--Beka

On Tue, Jul 2, 2024 at 8:19 AM Riya Patadiya <riya.p...@caperminttechnologies.com> wrote:
I am new to Blockly blocks. I request you to suggest me some ways to arrange blocks directly into canvas from JavaScript generated code earlier.

--
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/54ba4715-17c3-48e3-97bc-de8c41f4b9fbn%40googlegroups.com.

Chittaranjan Nahak

unread,
Jul 9, 2024, 11:16:02 AM (13 days ago) Jul 9
to Blockly
Hi,
I am trying to convert the js to Blockly. So I know there is no predefined method but is there any work around available in blockly. 
In my application we have 2 tabs one is for blockly and another for Javascript. so any user who ever comfortable with Blockly can add blockly blocks and then click the save button so in the DB it will save both Blockly xml as well as Javascript.
Simillarly whoever comfortable in js writes the js code then then if user moves to Blockly tab then user can see the corresponding blockly blocks for the js and vice versa. 

earlier we are doing something like below to convert js to blockly but now I upgraded the blockly and it seems it is not supported any more.
var parseJavascriptToBlockly = function () {
    var javascript_code = javascriptContent.getValue();
    try {
        var xmlDom = Blockly.JavaScript.importer.codeToDom(javascript_code, 'atomic'); //'pattern' is selected because on 'atomic' we have issues in blockly to javascript conversion.
        Blockly.Xml.domToWorkspace(xmlDom, ruleEngineGlobal.ruleEngineWorkspace);
        return "";
    } catch (e) {
        return e;
    }
};

Aaron Dodson

unread,
Jul 12, 2024, 6:27:07 PM (9 days ago) Jul 12
to Blockly
Hi,

It appears that you're using https://github.com/carloslfu/blocklify? Given that that library hasn't been updated for many years we've likely deprecated something it was relying on; if you could share the error message you're getting there might be a relatively straightforward fix.

- Aaron

Reply all
Reply to author
Forward
0 new messages