load blockly workspace with given json

990 views
Skip to first unread message

Khushbu Yeole

unread,
May 2, 2018, 6:12:04 AM5/2/18
to Blockly
Hi, 

I want my workspace to be default load by using JSON of default blocks/ custom blocks.

Please any suggestion?

Khushbu Yeole

unread,
May 2, 2018, 9:49:39 AM5/2/18
to Blockly
I want feature like if i create some logic in workspace and saved.(In JSON or XML format)
After that when i come back to blockly if i give my JSON or XML workspace should be reloaded with same view.

Please help me.

Andrew n marshall

unread,
May 2, 2018, 7:01:34 PM5/2/18
to blo...@googlegroups.com
Hi Khusubi,

I think you're asking about saving and reloading the blocks on the workspace. If so, the section on importing and exporting blocks has a couple of example snippets you can use. This will give you the blocks as an XML string, which you can store in cookies, localStorage, or on a server. When you return, you can retrieve the string and reload those blocks.

Let me know if you have additional questions.

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Khushbu Yeole

unread,
May 3, 2018, 2:25:29 AM5/3/18
to Blockly
Hi,

I did by storing xml in service.
while i do code like: 

        Blockly.mainWorkspace.clear();
        var newXml = Blockly.Xml.textToDom("My Xml here");
        Blockly.Xml.domToWorkspace(newXml, Blockly.mainWorkspace);
       
the 3rd line gives me empty array. Is there any another way to import blockly xml into workspace.
Can we this by using JSON?


On Wednesday, May 2, 2018 at 3:42:04 PM UTC+5:30, Khushbu Yeole wrote:

Andrew n marshall

unread,
May 3, 2018, 1:24:58 PM5/3/18
to blo...@googlegroups.com
That code looks correct.  Can you share your XML?

Blockly uses JSON for block definitions and event serialization, not workspace serialization.

--
Reply all
Reply to author
Forward
0 new messages