Constructing a Cylinder with Python

Hey all. I am trying to make a cylinder from two given points. I got it working nicely, by constructing a mesh with NMesh.GetRaw and adding a few verticies in key places. Then I did obj.Blender.Get( “Mesh”) with obj.RotY etc to orient it correctly. Unfortunately the reason I wanted to write this script was to have an array of these cylinders (coords are read from a text file) and I soon found out that when I did more than one Cylinder it would grab the wrong one because of the “Mesh” name above. So… I was thinking of just putting the verticies in their final positions, but quickly found that my powers of linear algebra were not up to the task.

I looked a meta balls, because a tubeX oriented correctly would work also, but I can’t figure out how to actually construct a meta ball purely from python.
So I guess my request is: could some one help me out with the needed linear algebra or tell me how to add an elem to the meta ball list?

Much Appreciated.
SquirrelSNuts

Here is the code I have so far:
I pointed out the rogue code.

import Blender
from Blender import *
import math
from math import *
import vecModule
from vecModule import *


class Cylinder:
  def __init__(self,p1=[0.0,0.0,0.0], p2=[0.0,0.0,1.0], name="bob2" ):
    me = NMesh.GetRaw()
 
    vec = makeVec( p1, p2 ) 

    n = 32
    rad = 0.3

    height = vecLen(vec)

    v1 = NMesh.Vert(0,0,height)
    v2 = NMesh.Vert(0,0,0)

    me.verts.append(v1)
    me.verts.append(v2)

    for i in range(0,n):
      x = rad*cos(i*2*pi/(n-1))
      y = rad*sin(i*2*pi/(n-1))

      v1 = NMesh.Vert(x,y,height)
      v2 = NMesh.Vert(x,y,0)
 
      me.verts.append(v1)
      me.verts.append(v2)
    #end loop

    #Faces
    #start with caps
    for i in range(2, 2*n):  #0 and 1 are the centers
      f = NMesh.Face()
  
      f.v.append( me.verts[i%2] )  #0 or 1 is center of cap
      f.v.append( me.verts[i]   )
      f.v.append( me.verts[i+2] )
      me.faces.append(f)
    #end loop

    #patch up the last few
    f = NMesh.Face()
    f.v.append( me.verts[-2] )
    f.v.append( me.verts[0] )
    f.v.append( me.verts[2] )
    me.faces.append(f)

    f = NMesh.Face()
    f.v.append( me.verts[-1] )
    f.v.append( me.verts[3] )
    f.v.append( me.verts[1] )


    
    #now side(s)
    for i in range(2, 2*(n-1), 2):
      f = NMesh.Face()
      f.v.append( me.verts[i])
      f.v.append( me.verts[i+1])
      f.v.append( me.verts[i+3])  #not sure if order matters...
      f.v.append( me.verts[i+2])  #...but just in case
      f.smooth = 1
 
      me.faces.append(f)
    #end loop

    #This is where the material stuff goes

    NMesh.PutRaw(me, name, 1)
    
    obj = Blender.Object.Get("Mesh")   <i><b>#Here is the problem!!</b></i>
    

    Sphvec = makeSph(vec)        #(r,phi,theta)
   
    obj.RotY = pi/2.0 - Sphvec[1]
    obj.RotZ = Sphvec[2] 
    
    obj.LocX = p1[0]
    obj.LocY = p1[1]
    obj.LocZ = p1[2]

  #end constructor