I'm trying to write a function to create an object made just out of vertices which is a spiral, kind of like these:
Here's my code:
def spiral(iterations=2,segs=20):
verts = []
faces = []
z=0
position = bpy.context.scene.cursor_location
print(bpy.context.scene.cursor_location)
deg2rad = math.pi / 180
gap = 360 / segs
for i in range(iterations):
for i in range(0, segs + 1):
deg = i * gap
rad = deg * deg2rad
x, y = math.cos(rad) * 5, math.sin(rad) * 5
verts.append((x,y))
for i in range(iterations):
faces.append((i, i+1))
mesh = bpy.data.meshes.new("Spiral")
object = bpy.data.objects.new("Spiral", mesh)
object.location = bpy.context.scene.cursor_location
bpy.context.scene.objects.link(object)
mesh.from_pydata(verts,[],faces)
mesh.update(calc_edges=True)
But for some reason it returns this in the Terminal:
<Vector (0.0000, 0.0000, 0.0000)>
Error: Array length mismatch (expected 126, got 84)
Traceback (most recent call last):
File "/Users/jacobgarby/Documents/Blender Things/Blender Files/python_meshes.blend/Text", line 48, in <module>
File "/Users/jacobgarby/Documents/Blender Things/Blender Files/python_meshes.blend/Text", line 45, in spiral
File "/Users/jacobgarby/Downloads/blender- 2/2.76.app/Contents/MacOS/../Resources/2.76/scripts/modules/bpy_types.py", line 414, in from_pydata
self.vertices.foreach_set("co", vertices_flat)
RuntimeError: internal error setting the array
Error: Python script fail, look in the console for now...