can blockly workspace be written to and read from disk?

74 views
Skip to first unread message

stephen eshelman

unread,
Sep 20, 2016, 2:51:02 PM9/20/16
to Blockly
can blockly workspace be written to and read from disk?

Brook Nichols

unread,
Sep 20, 2016, 4:26:47 PM9/20/16
to Blockly
The Blocks in your workspace can be retrieved as a string via Blockly.Xml.domToText (Blockly.Xml.workspaceToDom( Blockly.getMainWorkspace() ) ). Then you can do whatever file download/upload mechanism you choose. 

stephen eshelman

unread,
Sep 21, 2016, 12:34:43 PM9/21/16
to Blockly
Excellent, tyvm!

Neil Fraser

unread,
Sep 21, 2016, 12:58:48 PM9/21/16
to blo...@googlegroups.com
My suggestion is to avoid using Blockly.getMainWorkspace() wherever possible.  Many applications have more than one workspace on a page, which means Blockly.getMainWorkspace() might return the wrong one.  It's better to keep the workspace is a variable when it is created, and use that variable.

But this is tangential to the XML stuff, which is all correct.

--
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.



--

Wolfgang Koehler

unread,
Sep 25, 2016, 2:09:55 PM9/25/16
to Blockly
The file up- / down load is the tricky portion because of the browser security limitations. I'm using fileSaver.js (https://github.com/eligrey/FileSaver.js/)
Reply all
Reply to author
Forward
0 new messages