porting custom primitive to Bmesh how to ?

tryikng to convert an old script to make a new primitive from scratch

and getting some werid problems

here is the new converted script i made


 
import bpy,bmesh
 
from mathutils import Vector
from math import cos,sin,pi,degrees
from add_utils import AddObjectHelper, add_object_data
 
 
def add_object(v,e=[],f=[]):
 
 
 vertsData=[]
 facesData=[]
 
 ed = []
 me = bpy.data.meshes.new(name= "Fluo1")
 me.from_pydata(v, e, f )
             # useful doc when the mesh may be invalid.
 me.validate(verbose = True)
 add_object_data(bpy.context, me, operator = None)    
             # 
 
 
 fluolenght=4           # foot
 fluowidth=0.5           # foot
 fluoheight=4           # inches 
 
 xw=fluolenght/2.0           # Mesh drawn symetrical /  origin = 0,0,0  
               # so dim have to be 1/2 the value  + X /2 + X/2 = X
 
 yd=(fluowidth/2.0)
 
 zh=(fluoheight/12)/2.0
 
 nfin=10
 
# verts              0             1            2           3               4         5            6           7 
 vertsData=[(xw,-yd,-zh),(xw,-yd,zh),(-xw,-yd,zh),(-xw,-yd,-zh),(xw,yd,-zh),(xw,yd,zh),(-xw,yd,zh),(-xw,yd,-zh)]
 facesData=[(0,1,2,3),(4,7,6,5),(1,5,6,2),(2,6,7,3),(0,1,5,4)]
    # left      rigth     top        back       front     bottom
 
 
 
 
add_object(vertsData,[],f=[facesData])
 
 
 
 
 
 

not certain i get error on the verts list which is defined at the beginning

but should i show it in the first definition
me.from_pydata(v, e, f ) may be?

and what does it do it is to initialize the pydata may be ?

thanks for any help

this seems to be working
but not certain if this is the best way to port it


import bpy,bmesh
 
from mathutils import Vector
from math import cos,sin,pi,degrees
from add_utils import AddObjectHelper, add_object_data
 
 
 
def edit_mode_out():
 bpy.ops.object.mode_set(mode = 'OBJECT')
 
def edit_mode_in():
 bpy.ops.object.mode_set(mode = 'EDIT')
 
 
 
def add_object(v,e=[],f=[]):
 
 
 vertsData=[]
 facesData=[]
 ed = []
 
 
 fluolenght=4           # foot
 fluowidth=0.5           # foot
 fluoheight=4           # inches 
 
 xw=fluolenght/2.0           # Mesh drawn symetrical /  origin = 0,0,0  
               # so dim have to be 1/2 the value  + X /2 + X/2 = X
 
 yd=(fluowidth/2.0)
 
 zh=(fluoheight/12)/2.0
 
 nfin=10
 
# verts              0             1            2           3               4         5            6           7 
 vertsData=[(xw,-yd,-zh),(xw,-yd,zh),(-xw,-yd,zh),(-xw,-yd,-zh),(xw,yd,-zh),(xw,yd,zh),(-xw,yd,zh),(-xw,yd,-zh)]
 facesData=[(0,1,2,3),(4,7,6,5),(1,5,6,2),(2,6,7,3),(0,1,5,4)]
    # left      rigth     top        back       front     bottom
 
 
 
 print()
 print ('vertsData =',vertsData)
 print()
 print ('facesData =',facesData)
 
 ver=[]
 fac=[]
 
 for j in range(0, len(vertsData)):
  print ('vertsData[',j,'] =',vertsData[j])
  ver.append(Vector((vertsData[j])))
  print ('verts  v =',ver)
 
#  v.append(Vector((cos(i*pi/3),sin(i*pi/3),0)))
 
 print()
 print ('verts  v =',ver)
 print()
 
 
 me = bpy.data.meshes.new(name= "Fluo1")
 me.from_pydata(ver, [], facesData)
             # useful doc when the mesh may be invalid.
 me.validate(verbose = True)
 add_object_data(bpy.context, me, operator = None)    
             # 
 
 
###########
 
add_object([],[],[])
 
 
 
 

here i used the same old list of verts then converted to a list of vectors
and build a new face list

then made the Bmesh object

edited

i change the face list

seems that the same old list of faces can be used for Bmesh
which simplify it even more!

thanks