-
-
Save zeffii/10107460 to your computer and use it in GitHub Desktop.
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() |
Yep, good points to think about for me. This was a experimental so little thought was given to the type
check. I don't want to submit nodes that perform operations that can easily be done with existing nodes.
With the socket names I followed the style used by other nodes. data is generally lower case, But i can see why setting Skip would make sense.
The advantage vs ListMask is that it is easier to use.
With ListMask you have to create a pattern, say [0,0,0,1] to skip every 4th.
Capital case is the blender standard so lets follow that.
Changing the existing nodes breaks old layouts. At some point I think we should change them all but not right now.
Also, check that there is an output connection before doing the actual work.
Otherwise it looks good I think.
there is list item node, that gives the same result...
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.
yes, lets left node not commited. There is enogh stuff in list nodes section.
It can easily be done using ListMask, but I still think it is a useful node.
3 Comments:
I think it is better to use capital letter for socket name. so Data, Skip etc.
Line 55: isinstance is better idea than type data etc so: elif isinstance(data, (list,tuple)):
Also, an Other output like ListItem is a nice idea I think.