diff --git a/menu.py b/menu.py index 4d930dfbc82f5f49fb10f52a1fbfa9568fd23216..ba0953d9222ae17defaa31d3dad54e1d333fa927 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 diff --git a/nodes/__init__.py b/nodes/__init__.py index a51186250b9a55cda134987f8cee72392f1f48ab..dbe7b5e5d78be8e8b8833f43cd92f5bd1b21d3fa 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': [ diff --git a/nodes/basic_data/sort_blenddata.py b/nodes/basic_data/sort_blenddata.py new file mode 100644 index 0000000000000000000000000000000000000000..7284434e8fc1555844541fa35dcec1e7b1d681a1 --- /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)