1
$\begingroup$

To avoid some unnecessary OBJECT/EDIT mode toggle, i'd like to be able to perform some actions via Bmesh in object mode. Is it possible to update apply changes after a Bmesh action in object mode ? For exemple, i try to select an edge with this little code but, without update, the edge not selected.

import bpy
import bmesh

C = bpy.context
ob = C.object
me = ob.data
bm = bmesh.new()
bm.from_mesh(me)

bm.edges.ensure_lookup_table()
bm.edges[2].select = True

# need to update here

bm.free()
del bm
$\endgroup$
1
  • $\begingroup$ bm.to_mesh( me ), or as @jdk1.0 answered below, use the bmesh.from_edit_mesh( me ) method. Only after selecting, also run bm.select_flush( True ). $\endgroup$
    – TLousky
    Commented Aug 6, 2017 at 6:27

1 Answer 1

2
$\begingroup$

Try:

# need to update here
bm.to_mesh(me)

But then you'll need to switch to edit mode to see the selection.

As an alternative, you can do the selection entirely in edit mode with the following:

mesh = bpy.context.object.data
bm = bmesh.from_edit_mesh(mesh)

bm.edges.ensure_lookup_table()
bm.edges[2].select = True

bmesh.update_edit_mesh(mesh)
$\endgroup$

You must log in to answer this question.

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