Headless Workspace

191 views
Skip to first unread message

Julian

unread,
Jun 8, 2017, 2:03:32 PM6/8/17
to Blockly
Hey guys,

I want to test if a blockly-code-solution ist coded correctly. To reach that i want to rerun the solution code in a headless workspace with different values and the Main-Workspace should not change. 

I read the api already but it's not helping too much. So this is what i want to do:

1: parse the solution in xml and change the values [works]

2: return the changed xml-code to blockly-xml-dom [works]

3: rerun the code in javascript due to a headless workspace [doesn't work]

I wish it could work like that:

var changedXml = (new XMLSerializer()).serializeToString(xmlDoc);
  var xml = Blockly.Xml.textToDom(changedXml);
  var headless = new Blockly.Workspace();
  Blockly.Xml.domToWorkspace(headless, xml);
  var changedCode = Blockly.JavaScript.workspaceToCode(headless);
  headless.dispose();

  try {
  eval(changedCode);
} catch (e) {
alert(e);
}
 Thanks for your support.

Victor Ng

unread,
Jun 8, 2017, 2:22:12 PM6/8/17
to Blockly
This looks correct.

Could you post the JavaScript code that is being generated? What is the error that is printed from your code?

Julian

unread,
Jun 9, 2017, 4:31:21 AM6/9/17
to Blockly
Thanks for your fast reply Victor. 

At the moment the posted code is not creating any javascript because i get this error-line here:

Uncaught TypeError: Cannot read property '1' of undefined
    at new Blockly.Connection (blockly_blockly.js?hash=b464fb2…:909)  .... 

at Object.Blockly.Xml.domToBlockHeadless_

This error happens exactly with this line of code:

Blockly.Xml.domToWorkspace(headless, xml);
(Swapping the parameters doesn't help as well)

I think the problem here is that it's not 100 % clear how to create a headless workspace correctly.

Victor Ng

unread,
Jun 9, 2017, 2:22:22 PM6/9/17
to Blockly
If you could post a sample project that demonstrates the problem, it would be much easier to help debug.

Some places to start looking:
- check that the XML being passed in is correctly formed.
- check that the definitions for the blocks in your workspace have been loaded in JS prior to calling the code snippet.

I'd also try hardcoding a very basic workspace XML to see if that runs through that code snippet. Then, assuming that works successfully, slowly add block XML to eventually match the XML that's causing problems.

Rachel Fenichel

unread,
Jun 9, 2017, 3:56:40 PM6/9/17
to Blockly
Hi Julian,

There's a sample that uses a headless workspace.  Here's the code.

Cheers,
Rachel
Reply all
Reply to author
Forward
0 new messages