Skip to content

Instantly share code, notes, and snippets.

@nortikin
Last active August 29, 2015 14:02
Show Gist options
  • Save nortikin/c967b8f73886c1aef30b to your computer and use it in GitHub Desktop.
Save nortikin/c967b8f73886c1aef30b to your computer and use it in GitHub Desktop.
line.py
import bpy
from node_s import *
from util import *
class LineNode(Node, SverchCustomTreeNode):
''' Line '''
bl_idname = 'LineNode'
bl_label = 'Line'
bl_icon = 'OUTLINER_OB_EMPTY'
int_ = bpy.props.IntProperty(name = 'N Verts', description='Nº Vertices', default=2, min=2, options={'ANIMATABLE'}, update=updateNode)
step_ = bpy.props.FloatProperty(name = 'Step', description='Step length', default=1.0, options={'ANIMATABLE'}, update=updateNode)
def init(self, context):
self.inputs.new('StringsSocket', "Nº Vertices").prop_name = 'int_'
self.inputs.new('StringsSocket', "Step").prop_name = 'step_'
self.outputs.new('VerticesSocket', "Vertices", "Vertices")
self.outputs.new('StringsSocket', "Edges", "Edges")
def draw_buttons(self, context, layout):
pass
#layout.prop(self, "int_", text="Nº Vert")
#layout.prop(self, "step_", text="Step")
def update(self):
# inputs
if 'Nº Vertices' in self.inputs and self.inputs['Nº Vertices'].links:
Integer_ = SvGetSocketAnyType(self,self.inputs['Nº Vertices'])[0]
else:
Integer_ = [self.int_]
if 'Step' in self.inputs and self.inputs['Step'].links:
Step_ = SvGetSocketAnyType(self,self.inputs['Step'])[0]
if len(Integer_) > len(Step_):
fullList(Step_, len(Integer_))
X=[]
for j, k in enumerate(Integer_):
listVert = []
for i in range(k):
listVert.append(i*Step_[j])
X.append(listVert)
else:
Step = self.step_
X = [[Step*(i) for i in range(Integer)] for Integer in Integer_]
# outputs
if 'Vertices' in self.outputs and self.outputs['Vertices'].links:
points = []
for X_obj in X:
Y = [0.0]
Z = [0.0]
max_num = len(X_obj)
fullList(Y,max_num)
fullList(Z,max_num)
points.append(list(zip(X_obj,Y,Z)))
SvSetSocketAnyType(self, 'Vertices',points)
if 'Edges' in self.outputs and self.outputs['Edges'].links:
edg = []
for Integer in Integer_:
listEdg_obj = []
for i in range(Integer-1):
listEdg_obj.append((i, i+1))
edg.append(list(listEdg_obj))
SvSetSocketAnyType(self, 'Edges',edg)
def update_socket(self, context):
self.update()
def register():
bpy.utils.register_class(LineNode)
def unregister():
bpy.utils.unregister_class(LineNode)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment