-
-
Save zeffii/10107460 to your computer and use it in GitHub Desktop.
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 | |
outputs = self.outputs | |
if len(outputs['data'].links) == 0: | |
return | |
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 isinstance(data, (list, 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() |
yes, lets left node not commited. There is enogh stuff in list nodes section.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ListItem with an input of [0,3,7,11] and Other output gives the same result. Better way to generate Series for integers would help with this problem.