I created a program that define some vertices and faces and generate a cylinder in the Blender scene:
import bpy import math import mathutils points = 10 step = ((math.pi* 2) / points) x = 0 y = 0 current = 0 radius = 0.1 vertices =  edges =  faces =  n_points = 5 n_step = 0 n_dist = 0 for iterator in range(0,n_points): for count in range(0,points): x = math.sin(current) * radius y = math.cos(current) * radius vertices.append((0+n_step,x,y)) print("(",x,",",y,")") current += step for count in range(0,points): if(iterator >= 1): if(count != points-1): faces.append((count + iterator*points - points, count + iterator*points+1 - points, count + iterator*points + 1, count + iterator*points)) else: faces.append((count + iterator*points - points, count + iterator*points - (points-1)-points, count + iterator*points - (points-1),count + iterator*points)) n_step += 0.1 object_mesh = bpy.data.meshes.new("object_mesh") object_mesh.from_pydata(vertices, edges, faces) object_object = bpy.data.objects.new("object", object_mesh) scene = bpy.context.scene scene.objects.link(object_object)
Following this philosophy I would like to generate a structure that is not just a cylinder but it's a bit more complex and it's shown in the following figure:
Each of the line in the figure is a circle of
points points and they are connected exactly the same way I connected the points in the cylinder with my code. Generating the four sides shouldn't be a big problem but I can't understand how I can generate the oblique circles.
Just to make an example if this code create the upper part of the figure I am achieving, replacing the line
vertices.append((0+n_step,x-0.5,y-0.5)) can generate the down part.
With some inversions, I think I can generate the side parts but how can I manage the four oblique circles?
Notice that I have to generate the circles in order if I want to add the faces as I am doing now. Of course I am opened to alternatives.