3
$\begingroup$

I have an object named "Cube" selected, and I set the mode to EDIT via

cube = bpy.data.objects.get('Cube')
cube.select=True
bpy.ops.object.mode_set(mode='EDIT')

I want to subdivide each edge into 3 parts. In the editor, I can click Tools -> Subdivide, and then adjust the number of cuts below in a menu.

I cannot find any methods of the bmesh object class to do this, though.

$\endgroup$
3
$\begingroup$

Using BMesh.subdivide_edges(...)


Can use BMesh.subdivide_edges(...) with 3 cuts, and grid fill set to true.

import bpy
import bmesh
context = bpy.context
obj = context.edit_object
me = obj.data
bm = bmesh.from_edit_mesh(me)
bmesh.ops.subdivide_edges(bm,
        edges=bm.edges,
        use_grid_fill=True,
        cuts=3)
me.update()

There is an example in my answer here demonstrating how to use bmesh.ops.subdivide with a different number of cuts on each dimension.

$\endgroup$
1
$\begingroup$

I am getting used to the way the Python manual is written, and I realized the way you do this is simply

bpy.ops.mesh.subdivide(number_cuts=3)

As long as the cube is select and edit mode is active.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.