JSON toolbox || Add Block to workspace programmatically along with input values.

257 views
Skip to first unread message

Murali Manohar Varma

unread,
Nov 2, 2022, 7:01:06 PM11/2/22
to Blockly
I recently migrated from XML to JSON and wanted to know the similar functionality of the following.


Old Method : 
Toolbox in xml:

code.png

Function used to insert the xml directly to workspace. 

code.png



How to do it now with JSON toolbox.
Toolbox in JSON
code.png

How to add this particular block directly to the workspace.
Please help me.

Beka Westberg

unread,
Nov 3, 2022, 11:33:57 AM11/3/22
to blo...@googlegroups.com
Hello!

Sounds like you're looking for the Blockly.serialization.blocks.append method =) (to replace Blockly.Xml.appendDomToWorkspace)

I hope that helps! If you have any further questions please reply!
--Beka

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/23e5ae37-8f04-45a1-ab8e-d00fdf2a7427n%40googlegroups.com.

Aliyu

unread,
Nov 3, 2022, 3:17:19 PM11/3/22
to Blockly
Hello Murali Manohar Varma.
I am also on a project similar to yours,and 
thanks to Beka whom have been always there for all of us.
But i am stock and it seems you have all what i need .
Please kindly share me your code.
Thank you 

Murali Manohar Varma

unread,
Nov 4, 2022, 7:58:20 PM11/4/22
to Blockly
Beka, your a legend and i want you to know it. You literally a angel sent from heaven for Blockly team. I wish you all the happiness in the world. Thank you so much. Have a great life. Will come back soon.

Murali Manohar Varma

unread,
Dec 14, 2022, 4:02:04 PM12/14/22
to Blockly
Hi Beka, i have a small query, i am able to add the required block, but i am not able to add it to the desired position. My required position is, insert at last of all existing blocks, just like appendDomToWorkspace works. Can you give me some hint on this.

Beka Westberg

unread,
Dec 17, 2022, 12:13:14 PM12/17/22
to blo...@googlegroups.com
Hello!

Sorry for the late reply, looks like I missed this one. The JSON system doesn't have any built-in support for doing the exact thing that `appendDomToWorkspace` does. But there's no reason you can't implement it yourself.

Here's the source code for appendDomToWorkspace, the same basic steps of:
  - Get the bounding box
  - Deserialize the new blocks
  - Move them outside the bounding box

Will apply when using the JSON system. And this also gives you more control of how your blocks are positioned! E.g. they don't all have to be aligned vertically, they could be aligned horizontally or clustered into a square, etc.

If there is a lot of desire for this functionality, we may also consider adding it as a plugin!

I hope that helps! If you have any further questions please reply =)
--Beka

Reply all
Reply to author
Forward
0 new messages