Saru-no-Koshikake-Broken.py

import math
import bmesh

def deselect():
    for x in bpy.data.objects:
        x.select = False
#    bpy.ops.object.delete()

# n=disks m=fins q=lenth r0=min radius, r1=max radius, s=h to w ratio
def genVert(n, m, q, r0, r1, s):
    dR = (r1-r0)/float(n)
    d = 1.0
    for i in range(n+1):
        r = r0 + dR*float(i)
        middle = int((m+1)/2)
        offZ = q*float(i)/float(n)
        offX = -offZ
        yield(offX, 0.0, offZ)
        for j in range(middle+1):
            if d>0:
                t = float(j)*math.pi/float(m)
                yield(offX+r*math.cos(t), s*r1*math.sin(t), offZ)
            else:
                t = math.pi-float(j)*math.pi/float(m)
                yield(offX, s*r1*math.sin(t), offZ+r*math.cos(t))
        for j in range(middle+1,m+1):
            if d>0:
                t = float(j)*math.pi/float(m)
                yield(offX, s*r1*math.sin(t), offZ+r*math.cos(t))
            else:
                t = math.pi-float(j)*math.pi/float(m)
                yield(offX+r*math.cos(t), s*r1*math.sin(t), offZ)
        d *= -1.0
       
'''
    i = n
    offZ = q*float(i)/float(n)
    offx = -offZ
    yield(offX, 0.0, offZ)
    for j in range(m+1):
        t = float(j)*math.pi/float(m)
        yield(offX+r*math.cos(t), s*r*math.sin(t), offZ)
'''

def genEdge(n):
    for i in range(n-1):
        yield(i, i+1)
    
def genFace(n, m):
    for i in range(n+1):
        o = (m+2)*i
        for j in range(m):
            f = o + j + 1
            yield(o, f, f+1)
    
def main(n=10, m=12, q=1.0, r0=0.5, r1=1.0, s=1.0):
    deselect()
    verts = list(genVert(n, m, q, r0, r1, s))
    #edges = list(genEdge(len(verts)))
    faces = list(genFace(n, m))
    m = bpy.data.meshes.new('saruNoKoshikakeMesh')
    o = bpy.data.objects.new('saruNoKoshikake', m)
    bpy.context.scene.objects.link(o)#        m = context.scene.objects.active.data
#        bpy.ops.object.select_pattern(pattern="seamedLine")
    bpy.context.scene.objects.active = o
    bpy.context.scene.objects.active.select = True
    #m.from_pydata(verts, edges, [])
    m.from_pydata(verts, [], faces)
    m.update()
#        bm = bmesh.from_edit_mesh(m)
    return {'FINISHED'}