forked from ladybug-tools/ladybug-blender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generic_node.mustache
97 lines (85 loc) · 3.9 KB
/
generic_node.mustache
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import bpy
import ladybug_tools.helper
from bpy.props import StringProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode, zip_long_repeat
ghenv = ladybug_tools.helper.ghenv
class Sv{{{nickname}}}(bpy.types.Node, SverchCustomTreeNode):
bl_idname = 'Sv{{{nickname}}}'
bl_label = '{{{name}}}'
sv_icon = 'LB_{{{nickname_uppercase}}}'
{{#inputs}}
sv_{{{name}}}: StringProperty(name='{{{name}}}', update=updateNode, description='{{{description}}}')
{{/inputs}}
def sv_init(self, context):
self.width *= 1.3
{{#inputs}}
input_node = self.inputs.new('SvLBSocket', '{{{name}}}')
input_node.prop_name = 'sv_{{{name}}}'
input_node.tooltip = '{{{description}}}'
{{/inputs}}
{{#outputs}}
output_node = self.outputs.new('SvLBSocket', '{{{name}}}')
output_node.tooltip = '{{{description}}}'
{{/outputs}}
def draw_buttons(self, context, layout):
op = layout.operator('node.sv_lb_socket_name', text='', icon='QUESTION', emboss=False).tooltip = '{{{description}}}'
def process(self):
if not any(socket.is_linked for socket in self.outputs):
return
self.sv_output_names = [{{{output_name_list}}}]
for name in self.sv_output_names:
setattr(self, '{}_out'.format(name), [])
self.sv_input_names = [{{{input_name_list}}}]
self.sv_input_types = [{{{input_type_list}}}]
self.sv_input_defaults = [{{{input_default_list}}}]
self.sv_input_access = [{{{input_access_list}}}]
sv_inputs_nested = []
for name in self.sv_input_names:
sv_inputs_nested.append(self.inputs[name].sv_get())
for sv_input_nested in zip_long_repeat(*sv_inputs_nested):
for sv_input in zip_long_repeat(*sv_input_nested):
sv_input = list(sv_input)
for i, value in enumerate(sv_input):
if self.sv_input_access[i] == 'list':
if isinstance(value, (list, tuple)):
values = value
else:
values = [value]
value = [self.sv_cast(v, self.sv_input_types[i], self.sv_input_defaults[i]) for v in values]
if value == [None]:
value = []
sv_input[i] = value
else:
sv_input[i] = self.sv_cast(value, self.sv_input_types[i], self.sv_input_defaults[i])
self.process_ladybug(*sv_input)
for name in self.sv_output_names:
value = getattr(self, '{}_out'.format(name))
# Not sure if this hack is correct, will find out when more nodes are generated
#if len(value) == 0 or not isinstance(value[0], (list, tuple)):
# value = [value]
self.outputs[name].sv_set(value)
def sv_cast(self, value, data_type, default):
result = default if isinstance(value, str) and value == '' else value
if result is None and data_type == 'bool':
return False
elif result is not None and data_type == 'bool':
if result == 'True' or result == '1':
return True
elif result == 'False' or result == '0':
return False
return bool(result)
elif result is not None and data_type == 'int':
return int(result)
elif result is not None and data_type == 'double':
return float(result)
return result
def process_ladybug(self, {{{input_name_unquoted_list}}}):
{{{code}}}
for name in self.sv_output_names:
if name in locals():
getattr(self, '{}_out'.format(name)).append([locals()[name]])
def register():
bpy.utils.register_class(Sv{{{nickname}}})
def unregister():
bpy.utils.unregister_class(Sv{{{nickname}}})