For this line of code:

bm = bmesh.from_edit_mesh(mesh)

I am encountering the error 'ValueError: The mesh must be in editmode'

I am not certain how to fix this problem. For context, I am adapting the code solution at the bottom of this post, which was for an earlier version of Blender. My full code is here:

scene = bpy.context.scene
cam = bpy.data.objects['Camera']
obj = bpy.data.objects['Cube']
mesh = obj.data
mat_world = obj.matrix_world
cs, ce = cam.data.clip_start, cam.data.clip_end
bm = bmesh.from_edit_mesh(mesh)          
for v in bm.verts:
    co_ndc = world_to_camera_view(scene, cam, mat_world * v.co)
    #check wether point is inside frustum
    if (0.0 < co_ndc.x < 1.0 and 0.0 < co_ndc.y < 1.0 and cs < co_ndc.z <  ce):
        v.select = True
        v.select = False

bmesh.update_edit_mesh(mesh, False, False)
  • 1
    $\begingroup$ What do you'd like to do? How about bm = bmesh.from_mesh(mesh)? ... from the Text Editor > Python > Bmesh Simple. $\endgroup$
    – brockmann
    Commented Sep 10, 2019 at 19:51
  • $\begingroup$ @brockmann ... I edited my question to include the full block of code. Separately, bm=bmesh.from_mesh(mesh) throws the error "module 'bmesh' has no attribute 'from_mesh'" $\endgroup$
    – vndep
    Commented Sep 10, 2019 at 20:43
  • 1
    $\begingroup$ I don't get any error. I'd recommend starting by using the template @vndep Even the old script is still working, just replace * with @ and run it.... $\endgroup$
    – brockmann
    Commented Sep 10, 2019 at 21:02
  • 1
    $\begingroup$ How about entering edit mode before you copy the context scene $\endgroup$
    – HikariTW
    Commented Sep 10, 2019 at 22:32
  • $\begingroup$ That's the solution. It was a matter of adapting the code to a larger program and working out mode interactions. Thanks! $\endgroup$
    – vndep
    Commented Sep 11, 2019 at 23:41


You must log in to answer this question.

Browse other questions tagged .