Automatization of node creation
Created by: Durman
I have continued experiments with optimization API of node creation and reach much further last attempt. Next code is working:
from itertools import cycle
import bpy
from sverchok.data_structure import updateNode
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.utils.handling_nodes import NodeProperties, SocketProperties, SockTypes, WrapNode, initialize_node
node = WrapNode()
node.props.x = NodeProperties(bpy.props.FloatProperty(update=updateNode))
node.props.y = NodeProperties(bpy.props.FloatProperty(update=updateNode))
node.inputs.verts = SocketProperties(name='Vertices', socket_type=SockTypes.VERTICES, mandatory=True)
node.inputs.faces = SocketProperties(name='Faces', socket_type=SockTypes.STRINGS)
node.inputs.x_axis = SocketProperties(name='X axis', socket_type=SockTypes.STRINGS, prop=node.props.x)
node.inputs.y_axis = SocketProperties(name='Y axis', socket_type=SockTypes.STRINGS, prop=node.props.y)
node.outputs.verts = SocketProperties(name='Vertices', socket_type=SockTypes.VERTICES)
node.outputs.faces = SocketProperties(name='Faces', socket_type=SockTypes.STRINGS)
@initialize_node(node)
class SvTestNode(bpy.types.Node, SverchCustomTreeNode):
bl_idname = 'SvTestNode'
bl_label = 'Test node'
def process(self):
node.outputs.faces = node.inputs.faces
node.outputs.verts = [(v[0] + x, v[1] + y, v[2]) for v, x, y in zip(node.inputs.verts, cycle(node.inputs.x_axis), cycle(node.inputs.y_axis))]
It should looks magically.
Most advantage of current approach is it impacts on nothing. It does not change/add any node base classes. But new nodes can gain from it.
Also I have tried to use autocomplete as much as possible. At present most names will be hinted by IDE. Access to sockets can be get via dot notation like that node.inputs.verts
It is possible to set which sockets should be vectorized and all other works will be done automatically. The process
function should be coded as if Sverchok does not has vectorization.
In the end I expect to get less bugs and more new nodes coded, in the same time interval.