-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathsort_mk2.py
81 lines (66 loc) · 2.86 KB
/
sort_mk2.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
76
77
78
79
80
81
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
import bpy
from bpy.props import BoolProperty, IntProperty, StringProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import (updateNode, changable_sockets,
dataCorrect, levelsOflist)
class ListSortNodeMK2(SverchCustomTreeNode, bpy.types.Node):
''' List Sort MK2 '''
bl_idname = 'ListSortNodeMK2'
bl_label = 'List Sort'
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = 'SV_LIST_SORT'
replacement_nodes = [('SvListSortNode', None, None)]
level: IntProperty(name='level_to_count', default=2, min=0, update=updateNode)
typ: StringProperty(name='typ', default='')
newsock: BoolProperty(name='newsock', default=False)
def draw_buttons(self, context, layout):
layout.prop(self, "level", text="level")
def sv_init(self, context):
self.inputs.new('SvStringsSocket', "data")
self.inputs.new('SvStringsSocket', "keys")
self.outputs.new('SvStringsSocket', "data")
def sv_update(self):
if 'data' in self.outputs and self.inputs['data'].links:
# адаптивный сокет
inputsocketname = 'data'
outputsocketname = ['data']
changable_sockets(self, inputsocketname, outputsocketname)
def process(self):
if not self.outputs['data'].is_linked:
return
data_ = self.inputs['data'].sv_get()
levelinit = levelsOflist(data_)
data = dataCorrect(data_, nominal_dept=self.level).copy()
out_ = []
if not self.inputs['keys'].is_linked:
for obj in data:
out_.append(sorted(obj))
else:
keys_ = self.inputs['keys'].sv_get()
keys = dataCorrect(keys_, nominal_dept=1)
for d,k in zip(data,keys):
d.sort(key = lambda x: k.pop(0))
out_.append(d)
out = dataCorrect(out_,nominal_dept=levelinit-1)
self.outputs['data'].sv_set(out)
def register():
bpy.utils.register_class(ListSortNodeMK2)
def unregister():
bpy.utils.unregister_class(ListSortNodeMK2)