Bmesh examples for verts edges and faces ?

anyone has a script example for using new API for Bmesh

like using a cube and listing
verts edges and faces ?

just to get the feeling how it works ?

and is this going to break all scripts or old commands ?

i did a test not long ago and could not get anything for the faces uisng the normal faces command !

thanks

add cube
go into edit mode
run code:

import bpy
import bmesh

object = bpy.context.object
mesh = object.data
bmesh = bmesh.from_mesh(mesh)


for v in bmesh.verts:
    print(v)
    
for e in bmesh.edges:
    print(e)

for f in bmesh.faces:
    print(f)

see following post for links to api dox

http://lists.blender.org/pipermail/bf-python/2012-February/005808.html

i tried to import the module but get an error

so whats’ the SVN min number to get the new API for windows 32 bits?

thanks

I am not sure :slight_smile:
I build from from svn source
But try to get a nightly build somewhere (if they’re available)
Since the api is still being developed

ok got SVN 44463
and beginning to work

but the object has to be in edit mode
with old bpy data you could do it in the script

is there a way to do this with bmesh yet ?

thanks

Look here: http://www.pasteall.org/29533/python

nice example thanks

now in new Bmesh SVN

does it means that we have 2 data block type or only one ?

like when you i mport and object from 2.49 will it be converted into bmesh datablock or kept in the old format ?

and this would mean that all older way of making mesh like making new object vert/faces are broken !

have you seen a way to list edges/faces verts index and locations
for edges and faces in bmesh ?

seems to be something on page for bmesh.types.BMEdge
but have to find an example ho how to sue these new commands

thanks

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 )

i get therse which does not make sense

bmesh.types.BMEdge= <attribute ‘verts’ of ‘BMEdge’ objects>
bmesh.types.BMVert= <attribute ‘co’ of ‘BMVert’ objects>
bmesh.types.BMVert= <attribute ‘index’ of ‘BMVert’ objects>

so must be another way to list the co and index for eges and faces ?

thanks

got it the verts co and index

like this

for v in bmesh.verts:
print(’ vert=’,v,’ co=’,v.co,’ index=’,v.index)

but must be in edit mode ?

how do you make it in edit mode in the script ?

tried with this but many valuea are only addresses


 
for v in bmesh.verts:
    print(' vert=',v,' co=',v.co,' index=',v.index)
    
for e in bmesh.edges:
    print('edge =',e,' index =',e.index ,' verts=',e.verts)
    print (' other verts =',e.other_vert)
for f in bmesh.faces:
    print('face=',f,' edges=',f.edges,' index =',f.index,' verts=',f.verts)
 

thanks

you can use something like this to switch to edit mode

 if not bpy.context.object.mode == 'EDIT':
    bpy.ops.object.mode_set(mode = 'EDIT', toggle = False)

you can also use something like this to get the vertex coordinates:

for v in bmesh.verts:
    print("verts: ", v.co[:])

im trying to hide vertices as this should be possible in edit mode with bmesh but for some reason the vertices only get selected but not hidden:/ anyone can tell me what im doing wrong here?

if not bpy.context.object.mode == 'EDIT':
    bpy.ops.object.mode_set(mode = 'EDIT', toggle = False)
    bpy.context.scene.tool_settings.mesh_select_mode = (True, False, False) 

object = bpy.context.object
mesh = object.data
bmesh = bmesh.from_mesh(mesh)


for v in bmesh.verts:
    v.hide = True
    v.select = True
    print("selected: ", v.select)
    print("hidden: ", v.hide)