problem with adding a mesh need help

i ahe this script
where i add 2 mesh
the first one is working

but the second one is not working but it’s basically the same then the frit one
but giving an error on the vert or edge list ?

now i do ahve for the 2 mesh a list of list for vert and edges
but the second one does not like it for some reason!

at line 169 i did try the mesh add with only vert
or vert and edge and it does not change still get an error!
like expected 9 and get only 7
which i don’t see why ?

can someone help to make it work


 
 
 
 
import bpy
 
 
import mathutils
from math import *
from bpy.props import *
import  random
 
 
def AddSphericalRightTriangle1():
 
    name="CubicBeizercurve2"
    print (name)
 
 
    verts = []
    faces = []
    edges=[]
    medges=[]
 
    p0=[1 ,2 ,0]
    p1=[2,3,4 ]
#    p1=[3,4,0]
    p2=[5,6,7 ]
#    p2=[0,10,0]
#    p3=[1,10,0]
    p3=[4,5,0]
 
    print ()
 
    verts = [p0,p1,p2,p3]
    print (' 1  Verts =',verts,' Len =',len(verts))
    print ()
 
# vertices 
 
    medges.append([0, 1])
    edges.extend(medges)
    medges=[]
    medges.append([1, 2])
    edges.extend(medges)
    medges=[]
    medges.append([2, 3])
    edges.extend(medges)
    medges=[]
    print ('###############')
    print (' 1 edges =',edges,' Len =',len(edges))
 
    mesh = bpy.data.meshes.new(name)
    mesh.from_pydata(verts, edges, [])
 
    mesh.update()
 
    # Create a new Object.
 
    ob_new = bpy.data.objects.new(name, mesh)
    ob_new.data = mesh
    bpy.context.scene.objects.link(ob_new)
 
##############################################################
 
 
    print ('####################################  Last line ####################################  ')
    print ()
 
    ra4=10
 
#
    x0=5.0
    y0=3
    z0=2
    p0=[x0,y0,z0]
 
 
    x1=7.0
    y1=4.5
    z1=2.3
    p1=[x1,y1,z1]
 
    x2=7.3
    y2=3.9
    z2=1.5
    p2=[x2,y2,z2]
 
    print (' X0=',x0,'Y0=',y0,'z0=',z0,' Rad Sphere =',ra4)
    print ()
    print ('p0 =',p0)
    print ('p1 =',p1)
    print ('p2 =',p2)
    print ()
 
 
    # Calculate  midpoint of p0-p1
 
    xm1=(x1-x0)/2.0
    ym1=(y1-y0)/2.0
    zm1=(z1-z0)/2.0
 
    print ('Midpoint  po-p1   Xm',xm1,'Ym=',ym1,'z0=',zm1,' Rad Sphere =',ra4)
 
    lm=(xm1**2.0 +ym1**2.0+zm1**2.0)**0.5
    print (' lm =',lm)
    print ()
 
    ksph=ra4/lm
 
    am1=[ksph*xm1+ksph*ym1+ksph*zm1]
 
 
 
    # Draw the 2 segments on sphere
 
    verts=[]
    edges=[]
    medges1=[]
    edgeId1=0
    faces = []
 
    verts = [p0,am1,p1]
    print ('for  first edge  Verts=',verts,' Len =',len(verts))
    print ('edges1=',edges,' Len =',len(edges))
    print ()
    print ()
 
#         edgeId1                                 # Make segment edge
 
#    medges.append([0, 1])
    medges1.append([0, 1])
    edges.extend(medges1)
#    edges.append(medges1)
    medges1=[]
    edgeId1+= 1
 
 
    medges1.append([1, 2])
    edges.extend(medges1)
    medges1=[]
    edgeId1+= 1
 
    medges1.append([2, 0])
    edges.extend(medges1)
    print ('  3 - edges1=',edges,' Len =',len(edges))
    print ('  medge11=',medges1)
    medges1=[]
    edgeId1+= 1
 
    print ('  Verts=',verts,' Len =',len(verts))
    print ('4 edges1=',edges,' Len =',len(edges))
#    print ('Before  Verts = ',verts)
    print ()
    print (' edgeId1 =', edgeId1)
    print ()
 
    seg1=3
    del1=1.0/seg1
 
 
 
    named2="trigsegment1"
 
    print ('name=',named2)
    print ()
 
    mesh=[]
    mesh = bpy.data.meshes.new(named2)
#    mesh.from_pydata(verts, edges, [])
    mesh.from_pydata(verts, [], [])
    mesh.update()
 
    # Create a new Object.
 
    ob_new = bpy.data.objects.new(named2, mesh)
    ob_new.data = mesh
    bpy.context.scene.objects.link(ob_new)
 
 
 
 
 
AddSphericalRightTriangle1()
 
 
 
 
 
 
 
 
 
 
 

Thanks and happy 2.5

line 107


am1=[ksph*xm1+ksph*ym1+ksph*zm1]

should be:


am1=[ksph*xm1,ksph*ym1,ksph*zm1] # mind the comma instead of plus sign

always remember the from py_data operator requests a list of items with length 3
verts: list of 3
edges: list of 2
faces: list of 3 or 4

hope that helps

i must be becoming blind or dringking too much coke !

very clear this is not a triple but a single value
the vert list shows it as one value not a triple !
i used my magnifier to read it this time! LOL

the text in console is so small i can barely read
it must be font 6 may be
anyway to increase the size for this console output ?

but why do you say that verts need a minimum of 3 ?
i mean at the limit you could have ony one segment wiht only 2 vertices and one edge!

Thanks man now it should go fine

i meant to say that each item in the list of verts must be a tuple or list with length 3
with edges each must be two ints
and faces must be each 3 or 4 ints

hope that helps