bmesh

Hi everybody,
Does someone know how yo create a ngon from scratch (without bmesh.from_mesh) ?
I tried to create a face from with more than 4 vertecies, and then the mesh with from_pydata (verts, edges, faces) but it doesn’t work with more than 4 vertecies. Do we now have to have a function from_pydata for triangles and quad and another function for ngons ? Or is/will it be merged in one function ?
Thanks

Look at here: http://www.blender.org/documentation/blender_python_api_2_62_0/bmesh.types.html

Thanks,
But i already did look at that page, without any result. Everything i try returns an error ( couldn’t create instance or so…)
I was asking for a working peace of code to make a mesh with Ngons from coordinates list.
Hope someone did it, i only found examples of people modifying a “Bmeshed” mesh… :frowning:

ngon dont exist in normal blender only with bmesh !

salutations

Hi Ricky,
I had that error on all latest build from graphicall (with some i had a crash…). I don’t know if it’s due to api stability or to me. And i wanted to know if someone had a piece of code working to just build a mesh out of 5 vertecies in any of the latest builds.

Edit : so yes i have that error on bmesh builds of blender.

I think that the code is like that:


import bpy, bmesh
obj = bpy.context.object
mesh = obj.data
bm = bmesh.from_mesh(mesh)
vx=[[-1,1,1],[1,1,1], [-1,-1,1], [1,-1,1]] #add how verts you want
bm.faces.new(vx)

but don’t work, there is the following error:
ValueError: faces.new(verts): couldn’t create the new face, internal error

get same error on 463 !

may ahve to wait till we get a better ugrade on new SVN later on

bmesh is still a big alpha phase yet !

thanks

there are my 2 problems :

  1. it crashes or give an error
  2. No way to directly create a bmesh mesh. You have to transform an existing mesh.
    But i don’t like to hack to get things done.
    I would prefer a way like mesh.from_pydata that automatically create ngons for faces with more than 4 vertecies…

here is an example to create a mesh


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=[]):
    e = []
    m = bpy.data.meshes.new(name= "6cyc")
    m.from_pydata(v, e, f )
             # useful for development when the mesh may be invalid.
    m.validate(verbose = True)
    add_object_data(bpy.context, m, operator = None)    
             #???ERROR PKHG in AddSelf    setMaterial(bpy.context.active_object,pkhg_red_color)
 
r = 2
v = []
for i in range(6):
    v.append(Vector((cos(i*pi/3),sin(i*pi/3),0)))
 
add_object(v,[],f=[[0,1,2,3,4,5]])
 
print ('bmesh.types.BMEdge=', bmesh.types.BMEdge )
 
print ('bmesh.types.BMEdge=', bmesh.types.BMEdge.verts )
#print ('bmesh.types.BMEdge=', bmesh.verts )
 
print ('bmesh.types.BMVert=', bmesh.types.BMVert.co )
print ('bmesh.types.BMVert=', bmesh.types.BMVert.index )
 
 

but this creates an NGON 6 faces

don’t know if it can make other # faces Ngon?

salutations

@ricky
Thanks for your answer. That’s exactly what i tried (without the automatic vertecies coordinates generation) but it just crashed everytime the face had more than 4 vertecies indexed. Wich build are you using to get it work ?
Anyway really happy to hear it now works :slight_smile:
Happy 2.63 :smiley:

windows 44463

salutations

just tested on windows 44598 and working no errors

salutations

I had a need for this code and discovered it no longer works in 2.65.

So here is the revised 2.65 code, mainly import renames.


import bpy,bmesh

from mathutils import Vector
from math import cos,sin,pi,degrees
# Revised for 2.65 by Atom
#from bpy_extras import AddObjectHelper
from bpy_extras.object_utils import object_data_add
 
def add_object(v,e=[],f=[]):
    e = []
    m = bpy.data.meshes.new(name= "6cyc")
    m.from_pydata(v, e, f )
             # useful for development when the mesh may be invalid.
    m.validate(verbose = True)
    object_data_add(bpy.context, m, operator = None)    
             #???ERROR PKHG in AddSelf    setMaterial(bpy.context.active_object,pkhg_red_color)
 
r = 2
v = []
for i in range(6):
    v.append(Vector((cos(i*pi/3),sin(i*pi/3),0)))
 
add_object(v,[],f=[[0,1,2,3,4,5]])
 
print ('bmesh.types.BMEdge=', bmesh.types.BMEdge )
 
print ('bmesh.types.BMEdge=', bmesh.types.BMEdge.verts )
#print ('bmesh.types.BMEdge=', bmesh.verts )
 
print ('bmesh.types.BMVert=', bmesh.types.BMVert.co )
print ('bmesh.types.BMVert=', bmesh.types.BMVert.index )

It makes a bmesh hexagon plane.