How to create polyline and then poly loop with python. Bmesh fastest way.

Here is an example:

enter image description here


  • 2
    $\begingroup$ How about creating bm.verts, then connect them with bm.edges and finally extrude via bmesh.ops? $\endgroup$
    – CodeManX
    May 23, 2015 at 17:22

1 Answer 1


Create a polyline. (btw, imposing pure bmesh requirements on this is probably arbitrary, and using from_pydata is just as good)

import bpy
import bmesh
from mathutils import Vector

scene = bpy.context.scene 
meshes = bpy.data.meshes
objects = bpy.data.objects

# generate polyline 

bm = bmesh.new()
verts = [bm.verts.new((0, 0, z)) for z in range(5)]

for i in range(len(verts)-1):
    bm.edges.new([verts[i], verts[i+1]])

me = meshes.new('placeholder_mesh')
mesh_obj = objects.new('polyline', me)



Run this on a polyline:

import bpy
import bmesh
from mathutils import Vector

# Get the active mesh
obj = bpy.context.edit_object
me = obj.data

# Get a BMesh representation
bm = bmesh.from_edit_mesh(me)

bmesh.ops.extrude_edge_only(bm, edges=bm.edges[:])
bmesh.ops.translate(bm, vec=Vector((0,1.2,0)), verts=[v for v in bm.verts if v.select])

bmesh.update_edit_mesh(me, True)

See TextEditor -> Templates -> Python -> Simple Bmesh (edit mode) for the templates.

It might just be simpler to construct the polygon loop from scratch using from_pydata. It really depends on the final use-case

  • $\begingroup$ How to make polygon loop from scratch using from_pydata? $\endgroup$
    – mifth
    May 30, 2015 at 19:56
  • $\begingroup$ see first sentence in my answer. ( blender.stackexchange.com/questions/2407/… ) all you need are the vertex coordinates and the face index loops, building from scratch you are responsible for that. $\endgroup$
    – zeffii
    May 30, 2015 at 20:10
  • $\begingroup$ i think this is not what i need. I use editmode only. Could you check this issue too? blender.stackexchange.com/questions/31733/… $\endgroup$
    – mifth
    May 30, 2015 at 21:30
  • $\begingroup$ yeah, from_pydata isn't designed for interactive / edit mode mesh updates. I already looked at your other post, interesting problem. $\endgroup$
    – zeffii
    May 30, 2015 at 21:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .