Templates for Blockly

387 views
Skip to first unread message

Yukti Mehta

unread,
Jul 21, 2016, 3:30:12 AM7/21/16
to Blockly
How can I generate templates for the applications that I built through Blockly ? Is there anyway? Please help.

Thanks Much
Yukti Mehta


Daaron Dwyer

unread,
Jul 21, 2016, 10:44:25 AM7/21/16
to Blockly
I'm not sure exactly what you're asking for. There are shadow blocks and you can write the starting XML for your user, but I'm not sure exactly what you're asking for. Can you be a bit more specific about what a template is and how your user gets to it?

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

Yukti Mehta

unread,
Jul 22, 2016, 1:33:55 AM7/22/16
to Blockly
Thanks for the response. I am currently developing an application in which there is a button which can have templates of the series of blocks which are frequently used. PFA pic of the template that I want. Please help.


Thanks Much
Yukti Mehta
template.png

Wolfgang Koehler

unread,
Jul 22, 2016, 3:42:02 AM7/22/16
to Blockly
Here is how I do this:

  if (event.type == Blockly.Events.CREATE && manualAction) {
    var parentBlock = workspace.getBlockById(event.blockId);
    //add switches to the inputs of the BK
    if (parentBlock.type == "bk") {
      for (var i = 0; i <= 15; i++) {
        var childBlock = workspace.newBlock('px');
        if (i <= 9) {
          var parentConnection = parentBlock.getInput("I.D0" + i).connection;
          childBlock.setFieldValue('BK01.I.D0' + i, 'SwitchAddress');
        } else {
          var parentConnection = parentBlock.getInput("I.D" + i).connection;
          childBlock.setFieldValue('BK01.I.D' + i, 'SwitchAddress');
        }
        childBlock.initSvg();
        childBlock.render();
        var childConnection = childBlock.outputConnection;
        parentConnection.connect(childConnection);
      }
    }
    ...

Yukti Mehta

unread,
Jul 22, 2016, 6:04:59 AM7/22/16
to Blockly
Thank You for responding. But it would be great if you can send the link or can explain a bit where to put this code. Thanks in advance.

Thanks Much
Yukti Mehta

On Thursday, July 21, 2016 at 1:00:12 PM UTC+5:30, Yukti Mehta wrote:

Wolfgang Koehler

unread,
Jul 23, 2016, 1:01:39 AM7/23/16
to Blockly
There is no link. The logic is simple.

Whenever there is a CREATE event

if (event.type == Blockly.Events.CREATE && manualAction)

I check if the block created is of a certain type.

    var parentBlock = workspace.getBlockById(event.blockId);
    //add switches to the inputs of the BK
    if (parentBlock.type == "bk") {

If it is I automatically attach 16 other blocks to it


        var childBlock = workspace.newBlock('px');
        var parentConnection = parentBlock.getInput("I.D0" + i).connection;
        childBlock.initSvg();
        childBlock.render();
        var childConnection = childBlock.outputConnection;
        parentConnection.connect(childConnection);

and adjust the values of these blocks.


          childBlock.setFieldValue('BK01.I.D0' + i, 'SwitchAddress');

That's it. Instead of using the CREATE event you could use your button, create and connect all the blocks you want and adjust there values.

Happy coding
Reply all
Reply to author
Forward
0 new messages