Forum

Create B4W logic nodes by using Python

12 May 2016 18:06

I have (#9455).
Oh sorry, I haven't noticed

I got it! I gave you wrong recommendations(((
You should always specify sock parameter as "Jump_Dummy_Output_Socket".
So code snippet should look like this:

bpy.ops.node.b4w_logic_add_dyn_jump_sock('INVOKE_DEFAULT', node_tree="B4WLogicNodeTree", node="B4WLogicNode", sock="Jump_Dummy_Output_Socket")
Blend4Web Team - developer
12 May 2016 19:26
bjk
Konstantin,

Thank you very much!

Solved!
12 May 2016 23:24

Solved!
Glad to hear!
Looking forward to new interesting questions
Blend4Web Team - developer
06 December 2016 18:04
Reply to post of user bjk
Thank you Konstantin!

After searching I was able to create a small tree (as a start):

import bpy

scene = bpy.context.scene

scene.render.engine = 'BLEND4WEB'
scene.b4w_use_logic_editor = True
bpy.ops.node.new_node_tree(type='B4WLogicNodeTreeType', name="B4WLogicNodeTree")
scene.b4w_active_logic_node_tree = "B4WLogicNodeTree"

ntree = bpy.data.node_groups['B4WLogicNodeTree']
links=ntree.links

e_point = ntree.nodes.new(type='B4W_logic_node')
e_point.type = 'ENTRYPOINT'

regstore = ntree.nodes.new(type='B4W_logic_node')
regstore.type = 'REGSTORE'
regstore.floats['inp1'].float = 2 [s]regstore.param_number1 = 1[/s]
regstore.location = 160, 100

sw_select = ntree.nodes.new(type='B4W_logic_node')
sw_select.type = 'SWITCH_SELECT'
sw_select.location = 400, 100

move_to = ntree.nodes.new(type='B4W_logic_node')
move_to.type = 'MOVE_TO'
move_to.location = 650, 100

reroute1 = ntree.nodes.new("NodeReroute")
reroute1.location = 600, -100

reroute2 = ntree.nodes.new("NodeReroute")
reroute2.location = 380, -100

links.new(e_point.outputs[0], regstore.inputs[0])
links.new(regstore.outputs[0], sw_select.inputs[0])
links.new(sw_select.outputs[0], move_to.inputs[0])
links.new(sw_select.outputs[2], reroute1.inputs[0])
links.new(reroute1.outputs[0], reroute2.inputs[0])
links.new(reroute2.outputs[0], sw_select.inputs[0])

This is okay, I believe, but how do I select an object (the default cube) in Switch_Select and how do I add a new socket?

By the way, I watched the conference video. Congratulations!

Hi bjk,
I would like also add a new logic nodes.
Where do you add this code (above in the quote) ? Do you inject it in the "logic_node_tree.py" file or do you create an extra file for it ?

And where should this code be added:
bpy.ops.node.b4w_logic_add_dyn_jump_sock('INVOKE_DEFAULT', node_tree="B4WLogicNodeTree", node="B4WLogicNode", sock="Jump_Dummy_Output_Socket")

Thank you !
09 December 2016 21:45
bjk
Hi Sunnix,
It's all in the Blender file. Look at the attached blend file, run the script and browse the NodeTree to see the result.

For Blender Scripting tutorials take a look at
https://www.blender.org/manual/advanced/scripting/index.html
12 December 2016 14:12
Hi bjk,
great, thank you very much for your attachment.
I've downloaded it on my windows7 desktop, opened it and run the script "blad1". I became the first 3 nodes diplayed in the nodes blender aera but at this point (line 26 in the script) the console displays an error : KeyError: 'bpy_prop_collection[key]: key "vd" not found'
(see screenshot attached)
I use Blender 2.76b and Blend4Web 16.02 SDK. could it be the reason of this trouble ?
Or should I copy your blend file in a specific folder before opening it ?

Thank you for your advice
12 December 2016 22:32
bjk
I think it's because of the old SDK version. File logic_node_tree.py has been changed.
The latest version has the lines (from 1911)
                if "entryp" in self:
row.prop_search(self.variables_names["vd"], "variable",
self.id_data.nodes[self["entryp"]], 'variables', text=_('Var. name'))

In 'your' version you 'll find (from 1882)
                if "entryp" in self:
row.prop_search(self, "param_var_dest",
self.id_data.nodes[self["entryp"]], 'variables', text=_('Var. name'))

So in the script you can change line 26
regstore.variables_names['vd'].variable = "R2" 

into
regstore. param_var_dest = ”R2”
After line 26 you will certainly get more errors like this. Open the logic_node_tree files of both versions to find out what you have to change, or just download the latest SDK version
12 December 2016 22:46
Nice to see people interested in this topic
Blend4Web Team - developer
13 December 2016 17:36
Hi bjk,
Thank you very much for your help !
I'll download the last version to make it. Thanks again
 
Please register or log in to leave a reply.