forked from nortikin/sverchok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_Series.py
75 lines (60 loc) · 2.54 KB
/
node_Series.py
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
import bpy
from node_s import *
from util import *
class GenSeriesNode(Node, SverchCustomTreeNode):
''' Generator series '''
bl_idname = 'GenSeriesNode'
bl_label = 'List Series'
bl_icon = 'OUTLINER_OB_EMPTY'
start_ = bpy.props.FloatProperty(name = 'start', description='start', default=0, options={'ANIMATABLE'}, update=updateNode)
stop_ = bpy.props.FloatProperty(name = 'stop', description='stop', default=10, options={'ANIMATABLE'}, update=updateNode)
step_ = bpy.props.FloatProperty(name = 'step', description='step', default=1, options={'ANIMATABLE'}, update=updateNode)
def init(self, context):
self.inputs.new('StringsSocket', "Start", "Start")
self.inputs.new('StringsSocket', "Stop", "Stop")
self.inputs.new('StringsSocket', "Step", "Step")
self.outputs.new('StringsSocket', "Series", "Series")
def draw_buttons(self, context, layout):
layout.prop(self, "start_", text="start")
layout.prop(self, "stop_", text="stop")
layout.prop(self, "step_", text="step")
def update(self):
# inputs
if 'Start' in self.inputs and self.inputs['Start'].links:
tmp = SvGetSocketAnyType(self,self.inputs['Start'])
Start = tmp[0][0]
else:
Start = self.start_
if 'Stop' in self.inputs and self.inputs['Stop'].links:
tmp = SvGetSocketAnyType(self,self.inputs['Stop'])
Stop = tmp[0][0]
else:
Stop = self.stop_
if 'Step' in self.inputs and self.inputs['Step'].links:
tmp = SvGetSocketAnyType(self,self.inputs['Step'])
Step = tmp[0][0]
else:
Step = self.step_
# outputs
if 'Series' in self.outputs and len(self.outputs['Series'].links)>0:
if not self.outputs['Series'].node.socket_value_update:
self.inputs['Series'].node.update()
#print (Start, Stop, Step)
if Step < 0:
Step = 1
if Stop < Start:
Stop = Start+1
series = [c for c in self.xfrange(Start, Stop, Step)]
SvSetSocketAnyType(self,'Series', [series])
def xfrange(self, start, stop, step):
while start < stop:
yield start
start += step
def update_socket(self, context):
self.update()
def register():
bpy.utils.register_class(GenSeriesNode)
def unregister():
bpy.utils.unregister_class(GenSeriesNode)
if __name__ == "__main__":
register()