# Use the bevel-tool from python script

I want to use the bevel-tool to add a face between two other faces. The bevel-tool should use the selected edge(s) as geometry.location is given via a selected edge.

This is what I have

This is what I want

And how can I set a enum-value? I tried offset_type='OFFSET' but I get the error that int was expected.

Script:

import bpy, bmesh
from mathutils import Vector
obj = bpy.context.object
bm = bmesh.new()
bm.from_mesh(obj.data)
bm.verts.ensure_lookup_table()

selected_edge = None
for edge in bm.edges:
if edge.select:
selected_edge = edge
print("edge", edge)

print("selected_edge", selected_edge)

bpy.ops.object.mode_set(mode='OBJECT') # only working in object mode
faces = bmesh.ops.bevel(bm,
geom=[selected_edge],
offset=0.2,
offset_type='OFFSET',
segments=1,
profile=0.5,
vertex_only=False,
clamp_overlap=True,
material=-1)

print("faces", faces)

bm.to_mesh(obj.data)

• Question edited. – Hamburml Aug 10 '15 at 16:06
• Bmesh operators use integer constants instead of string enum keys. They are defined in the C code, and there's currently no other way than to find the definition in the C code and use the found values in the Python script. You may want to define some variables to make the numbers more descriptive. See here: developer.blender.org/diffusion/B/browse/master/source/blender/… – CoDEmanX Aug 11 '15 at 0:03

You can find out the answer to this in several ways. Here's what I did:

1. Use the UI tool (mark the middle edge then press CtrlB to bevel).
2. Go to the info panel (above the 3D view on the default layout), and open it up a little bit. Not always, but often, using the UI commands and operators will print out the command used in the info panel. Here we can see that the bpy.ops.mesh.bevel operator was used.
3. To further explore this command and its documentation, open the python console. Type in:

bpy.ops.mesh.bevel(

Then press CtrlSpace to see the autocompleted documentation for this operator. In this case:

bevel()
bpy.ops.mesh.bevel(
offset_type   = 'OFFSET',
offset        = 0,
segments      = 1,
profile       = 0.5,
vertex_only   = False,
clamp_overlap = False,
loop_slide    = True,
material      = -1
)


This shows you all the parameters and their defaults, you can then experiment with other values and search for this operator in the official docs to review any additional information you might need.

The parameter "geom" must be a list of edges AND their vertices, compare: