Is there a way to get blocks definition from AI and add it to custom blockly workspace?

Is it possible to get all available blocks definition from the app inventor and add it to another custom blockly workspace.

Example: I want component_set_get definition in JSON or in JS.

1 Like

No you can not get blocks defination

2 Likes

You can get blocks defination from my website I have created almost half block defination of appinventor
https://block-2-code.web.app/
Just go in this website and click Ctrl+U you will got blocks defination

3 Likes

I think you may want to have a look in the blockly folder of Appinventor 2 Sources.

4 Likes

Yeah this is a good idea

1 Like

Hi, I think you can probably get something in this directory's .js files :point_down:
appinventor-sources\appinventor\blocklyeditor\src\blocks
as in this dir. we could get the code of all the blocks is JS(JavaScript)...

image

4 Likes

Actually, Its different. I too don't know what these two different variants are called but they're different and see this:


Code for image block in B2C(Block to Code)

<block type="logic_compare"></block>

Code for image block in App Inventor

Blockly.Blocks['logic_compare'] = {

  // Comparison operator.

  category: 'Logic',

  helpUrl: function () {

    var mode = this.getFieldValue('OP');

    return Blockly.Blocks.logic_compare.HELPURLS()[mode];

  },

  init: function () {

    this.setColour(Blockly.LOGIC_CATEGORY_HUE);

    this.setOutput(true, Blockly.Blocks.Utilities.YailTypeToBlocklyType("boolean", Blockly.Blocks.Utilities.OUTPUT));

    this.appendValueInput('A');

    this.appendValueInput('B')

        .appendField(new Blockly.FieldDropdown(this.OPERATORS), 'OP');

    this.setInputsInline(true);

    // Assign 'this' to a variable for use in the tooltip closure below.

    var thisBlock = this;

    this.setTooltip(function () {

      var mode = thisBlock.getFieldValue('OP');

      return Blockly.Blocks.logic_compare.TOOLTIPS()[mode];

    });

  },

  // Potential clash with Math =, so using 'logic equal' for now

  typeblock: [{translatedName: Blockly.Msg.LANG_LOGIC_COMPARE_TRANSLATED_NAME}]

};

Blockly.Blocks.logic_compare.TOOLTIPS = function () {

  return {

    EQ: Blockly.Msg.LANG_LOGIC_COMPARE_TOOLTIP_EQ,

    NEQ: Blockly.Msg.LANG_LOGIC_COMPARE_TOOLTIP_NEQ

  }

};

Blockly.Blocks.logic_compare.HELPURLS = function () {

  return {

    EQ: Blockly.Msg.LANG_LOGIC_COMPARE_HELPURL_EQ,

    NEQ: Blockly.Msg.LANG_LOGIC_COMPARE_HELPURL_NEQ

  }

};

Blockly.Blocks.logic_compare.OPERATORS = function () {

  return [

    [Blockly.Msg.LANG_LOGIC_COMPARE_EQ, 'EQ'],

    [Blockly.Msg.LANG_LOGIC_COMPARE_NEQ, 'NEQ']

  ];

};
4 Likes

I think you do not know how I used that
I used that from directly Blockly but appinventor do not do oike that they create custom ly. AppInventor create custom = block and I create blockly = block but both blocks do samething

2 Likes

Thank you @Faraz_Firoz, @SRIKAR_B.S.S, @Pradevel for your response. I got a rough idea from https://block-2-code.web.app to implement it.

4 Likes

Yeah, exactly...
Thats what I'm saying both code isn't same, as they're 2 different variants of Google Blockly but result of these both ones is the same.

Good, hope you get something from Block to Code(from Funmora Developers Inc.)

1 Like

Blockly is block based programming language tool that helps students or anyone who doesn't know about programming.

For blockly generally you need block definition and customer generator for code generation.

For more tutorial you can follow guide provided by Google and use blockly Dev tool for creating a block.

https://blockly-demo.appspot.com/static/demos/blockfactory/index.html

2 Likes

I think there is no any difference between default blocks provided by Google and blocks created by you.

1 Like

Yeah, you are right

Just be aware that some of our blocks/fields rely on semantics that are slightly different in App Inventor than in core Blockly. This may cause problems down the line if the block in question relies on these different behaviors.

2 Likes

especially I think component.js relies on the Appinventor backend

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.