3
$\begingroup$

When you extrude the only face of a plane via the GUI you get a (closed) cube. If you do the same thing using bmesh you get a cube that is open on the bottom side.

bmesh extrude vs operator extrude

I am trying to achieve the normal result through bmesh. (using regular operators is not an option because the mesh is still not linked to the scene). Right now I duplicate the original face before extrusion, extrude, and then remove doubles.

allfaces = bm.faces[:]
bmesh.ops.duplicate(bm, geom=allfaces)
r = bmesh.ops.extrude_discrete_faces(bm, faces=allfaces)
bmesh.ops.translate(bm, vec=Vector((0,0,height)), verts=r['faces'][0].verts)
bmesh.ops.remove_doubles(bm, verts=bm.verts[:], dist=0.01)

This however doesn't strike me as a very elegant way to do it. Is there some other way?

$\endgroup$

2 Answers 2

4
$\begingroup$

You don't need to duplicate the geometry prior to extruding (this will remove the need for removing doubles as well), and using bmesh.ops.extrude_face_region is what you're looking for to generate a closed mesh from the extruded face/s.

enter image description here

This worked code fine with a 1-face plane with its sole face selected in edit mode:

import bpy, bmesh
from mathutils import Vector

bm      = bmesh.from_edit_mesh( bpy.context.object.data )
newGeom = bmesh.ops.extrude_face_region( bm, geom = bm.faces, use_select_history = True )

bmesh.ops.translate( bm, vec = Vector((0,0,1)), verts = bm.select_history[0].verts )

bmesh.update_edit_mesh( bpy.context.object.data )
$\endgroup$
0
4
$\begingroup$

And here is the code that I finally used, and that doesn't require the vertices to be selected.

r = bmesh.ops.extrude_face_region(bm, geom=bm.faces[:])
verts = [e for e in r['geom'] if isinstance(e, bmesh.types.BMVert)]
bmesh.ops.translate(bm, vec=Vector((0,0,height)), verts=verts)
$\endgroup$

You must log in to answer this question.

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