Created
April 8, 2014 10:23
-
-
Save anonymous/10107454 to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
from node_s import * | |
from util import * | |
''' | |
List skipping allows for a convenient way to drop every nth list element. | |
This is useful when constructing polygons using 2d lists of vertex indices | |
where every nth element must be dropped because it would contribute to an | |
invalid (wrapped around) polygon. | |
''' | |
class ListSkipNode(Node, SverchCustomTreeNode): | |
''' List Skip Node ''' | |
bl_idname = 'ListSkipNode' | |
bl_label = 'List Skip' | |
bl_icon = 'OUTLINER_OB_EMPTY' | |
level = bpy.props.IntProperty( | |
name='level_to_Skip', default=2, min=1, update=updateNode) | |
typ = bpy.props.StringProperty(name='typ', default='') | |
newsock = bpy.props.BoolProperty(name='newsock', default=False) | |
skip = bpy.props.IntProperty(name='start', default=0, update=updateNode) | |
def draw_buttons(self, context, layout): | |
layout.prop(self, "level", text="level") | |
layout.prop(self, "skip", text="Skip") | |
def init(self, context): | |
self.inputs.new('StringsSocket', 'data', 'data') | |
self.inputs.new('StringsSocket', 'skip', 'skip') | |
self.outputs.new('StringsSocket', 'data', 'data') | |
def update(self): | |
inputs = self.inputs | |
if 'data' in inputs and (len(inputs['data'].links) > 0): | |
inputsocketname = 'data' | |
outputsocketname = ['data'] | |
changable_sockets(self, inputsocketname, outputsocketname) | |
data = SvGetSocketAnyType(self, inputs['data']) | |
output = self.skipNth(data, self.level) | |
SvSetSocketAnyType(self, 'data', output) | |
def skipNth(self, data, level): | |
level -= 1 | |
skip = self.skip | |
if level: | |
return [self.skipNth(l, level) for l in data] | |
elif type(data) in [type([]), type(tuple())]: | |
return [i for idx, i in enumerate(data) if (idx-skip) % (skip+1)] | |
else: | |
return [] | |
def register(): | |
bpy.utils.register_class(ListSkipNode) | |
def unregister(): | |
bpy.utils.unregister_class(ListSkipNode) | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment