I'm trying to write a script to bisect Ngon rectangles, horizontally or vertically, at a given percentage of the distance along their sides. (The sides may consist of more than one edge).
Some of the script involves finding the right edges to cut, and moving the new vertices to the right place, but I hope this is a minimal expression of my problem:
ob = bpy.context.object me = ob.data bm = bmesh.new() bm.from_mesh(me) bm.edges.ensure_lookup_table() e1 = bm.edges e2 = bm.edges ret = bmesh.ops.subdivide_edges(bm, edges=[e1], cuts=1) v1 = ret['geom_inner'] ret = bmesh.ops.subdivide_edges(bm, edges=[e2], cuts=1) v2 = ret['geom_inner'] bmesh.ops.connect_verts(bm, verts=[v1,v2]) bm.to_mesh(me) me.update() bm.free()
(Here, I've hard-coded the edge selections)
bmesh.ops.connect_verts(bm,verts = [v1,v2]) generates an error: '..BMVert has been removed..', which is perhaps understandable, but how would I keep track of
v1,the vertex generated by the first cut? If I run this snippet without the connect, the vertices appear just fine in the updated mesh, so they are there, somewhere.
- I'm in 2.79
- The mesh starts in Object Mode (does that make a difference?)