adding newly created vertices to an existing mesh

I am creating my own spin script as opposed to using the spin tool because no matter what settings I use for the center axis, when calling bpy.ops.mesh.spin(…), it still would spin the mesh around the cursor. I have been able to create my own style using a bit of trigonometry. The problem I am now having is that I have created all the vertices coordinates into a list, but I do not know how I can add this list to the existing mesh. I have tried using bpy.ops.mesh.extrude_region_move(…) but, because I need the new coordinates of the extruded vertex to calculate the next spin, I get an error stating index out of range. So this is where I came up with keeping track of the new spin calculations and saved it into a verts list. Here is my code…


verts = []
#please note selVerts has already been calculated and is not included
for sel in selVerts :
    v1 = sel.co.copy()
    v2 = bpy.data.objects['Point'].location
    verts.append([])
    for i in range(4) :
        v = v2-v1
        q = v.to_track_quat('X', 'Z')
        qMat = q.to_matrix()
        fVec = qMat * Vector((1,0,0))
        myTrans = fVec * v.magnitude
        
        rotForward=Vector((0,-1,0))
        rotAng = qMat*rotForward 
        qMat.rotate(Euler(rotAng*radians(22.5), 'XYZ'))
        
        locForward=Vector((-1,0,0))
        wordForward = qMat * locForward
        myTrans += wordForward * v.magnitude
        v1 += myTrans
        verts[-1].append(v1.copy())

any idea how I could add these new vertices to an existing mesh would be a big help

Also see my facade library over at BlendSwap, which has a script file includes that creates an arch over tow selected vertices using a similar approach as you do.

okay, I think I might of worded my question wrong. After looking at hotzst’s script, it apears that although the script does adds new faces to an existing mesh, it completes this prior to creating the object. What I need is something that can link new mesh data to an existing object that has mesh data already added to. I am sorry for the confusion.

Here is a newly updated script I ame working on. All I need now is to be able to add the calculated mesh to the existing object. Here is the code.


import bpy, mathutils, math, os
from mathutils import *
from math import *

os.system('cls')
mag = 0.005 - 0.00039 
theta = radians(22.5)

==>this is the object the the new mesh needs to be added to<==
ob = bpy.context.object

dat = ob.data
verts = {}
for v in dat.vertices :
    v1 = dat.vertices[1].co.copy()
    v2 = bpy.data.objects['Point'].location.copy()
    dist = v2-v1
    dist.normalize()
    right = Vector((0,0,1)).cross(dist)
    right.normalize()
    backward = right.cross(Vector((0,0,1)))
    backward.normalize()
    forward = backward * -1
    up = Vector((0, 0, 1))
    
    mat3 = Matrix.Rotation(theta, 3, right)
    f = mat3 * forward
    center = f * mag
    
    verts[v.index] = []
    for i in range(3) :
        mat3.rotate(Euler(right*theta, 'XYZ'))
        f = mat3 * forward 
        center = f * mag
        verts[v.index].append([i+(v.index*4), center + v1 - (forward*mag)])

vertCoords = []
vertOrder = []
faces = []
#put the verts in drawing order
for v in range(len(dat.vertices)-1) :
    for i in range(2) :
        vertOrder.append([verts[v][i], verts[v+1][i], verts[v+1][i+1], verts[v][i+1]])

for v in vertOrder :
    startCount = len(vertCoords)
    vertCoords.externd([a[1] for a in v])
    ids = [i + startCount for i in range(len(v))]
    faces.append(tuple(ids))