From 0d5f6f784e9465665d34f89aab023f7ad89795ab Mon Sep 17 00:00:00 2001 From: Kosvor Date: Mon, 27 Apr 2015 12:48:37 +0300 Subject: [PATCH 1/3] Create sort_blenddata.py --- nodes/basic_data/sort_blenddata.py | 67 ++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 nodes/basic_data/sort_blenddata.py diff --git a/nodes/basic_data/sort_blenddata.py b/nodes/basic_data/sort_blenddata.py new file mode 100644 index 000000000..7284434e8 --- /dev/null +++ b/nodes/basic_data/sort_blenddata.py @@ -0,0 +1,67 @@ +# ##### 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 EnumProperty +from sverchok.node_tree import SverchCustomTreeNode +from sverchok.data_structure import (updateNode) + + +def Obm(m): + m = [(i,i,"") for i in m] + return m + + +class SvSortObjsNode(bpy.types.Node, SverchCustomTreeNode): + ''' Sort Objects ''' + bl_idname = 'SvSortObjsNode' + bl_label = 'sort_dataobject' + bl_icon = 'OUTLINER_OB_EMPTY' + + M = ['location.x','location.y','location.z','name'] + Modes = EnumProperty(name="sortmod", default="location.x", items=Obm(M), update=updateNode) + + def sv_init(self, context): + self.inputs.new('StringsSocket', 'Object') + self.inputs.new('StringsSocket', 'CustomValue') + self.outputs.new('StringsSocket', 'Object') + + def draw_buttons(self, context, layout): + if not self.inputs['CustomValue'].is_linked: + layout.prop(self, "Modes", "Sort") + + def process(self): + if self.outputs['Object'].is_linked: + X = self.inputs['Object'].sv_get() + if self.inputs['CustomValue'].is_linked: + Y = self.inputs['CustomValue'].sv_get()[0] + else: + Y = eval("[i."+self.Modes+" for i in X]") + X.sort(key=dict(zip(X, Y)).get) + self.outputs['Object'].sv_set(X) + + def update_socket(self, context): + self.update() + + +def register(): + bpy.utils.register_class(SvSortObjsNode) + + +def unregister(): + bpy.utils.unregister_class(SvSortObjsNode) -- GitLab From 6d1f8bb10a45e822fb3b6c8d30624377f31664e9 Mon Sep 17 00:00:00 2001 From: Kosvor Date: Mon, 27 Apr 2015 12:49:38 +0300 Subject: [PATCH 2/3] Update __init__.py --- nodes/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nodes/__init__.py b/nodes/__init__.py index a51186250..dbe7b5e5d 100644 --- a/nodes/__init__.py +++ b/nodes/__init__.py @@ -39,7 +39,8 @@ nodes_dict = { 'cache', 'getsetprop', 'get_blenddata', - 'set_blenddata' + 'set_blenddata', + 'sort_blenddata' ], 'basic_debug': [ -- GitLab From e8868e43810686b4afb07d085f67967862a1f95c Mon Sep 17 00:00:00 2001 From: Kosvor Date: Mon, 27 Apr 2015 12:50:38 +0300 Subject: [PATCH 3/3] Update menu.py --- menu.py | 1 + 1 file changed, 1 insertion(+) diff --git a/menu.py b/menu.py index 4d930dfbc..ba0953d92 100644 --- a/menu.py +++ b/menu.py @@ -257,6 +257,7 @@ def make_node_cats(): ["SvCSGBooleanNode", "CSG Boolean"], ["SvGetDataObjectNode", "Get ObjectID"], ["SvSetDataObjectNode", "Set ObjectID"], + ['SvSortObjsNode', "Sort ObjectID"], ] return node_cats -- GitLab