Cut big mesh into multiple smaller segments (Blender 5.0)

Before blender 5.0 I could use the script script below to split a mesh into smaller parts:

bpy.ops.object.mode_set(mode='EDIT')
bmNavMesh = bmesh.from_edit_mesh(ob_for_convert.data)
edges = []

for i in range(-10, 10, 1):
		ret = bmesh.ops.bisect_plane(bmNavMesh, geom=bmNavMesh.verts[:]+bmNavMesh.edges[:]+bmNavMesh.faces[:], plane_co=(i*100,0,0), plane_no=(-1,0,0))
		bmesh.ops.split_edges(bmNavMesh, edges=[e for e in ret['geom_cut'] if isinstance(e, bmesh.types.BMEdge)])

for i in range(-10, 10, ):
		ret = bmesh.ops.bisect_plane(bmNavMesh, geom=bmNavMesh.verts[:]+bmNavMesh.edges[:]+bmNavMesh.faces[:], plane_co=(0,i*100,0), plane_no=(0,1,0))
		bmesh.ops.split_edges(bmNavMesh, edges=[e for e in ret['geom_cut'] if isinstance(e, bmesh.types.BMEdge)])

bmesh.update_edit_mesh(ob_for_convert.data)
bmNavMesh = bmesh.from_edit_mesh(ob_for_convert.data)
bmesh.ops.remove_doubles(bmNavMesh, verts=bmNavMesh.verts[:], dist=0.0001)
bmesh.update_edit_mesh(ob_for_convert.data)

bpy.ops.object.mode_set(mode='OBJECT')                           
me = ob_for_convert.to_mesh()

But now that I’m on blender 5.0 this script crashes on:
bpy.ops.object.mode_set(mode='EDIT')

I am wondering if I should fix this script for Blender 5.0 or if there are new ways to do this.

The reason I’m cutting the mesh up like this is this is that they are used for a navmesh in an engine that loads them in small non overlapping segments.

Welcome :tada:

…this is some kind of strange because bpy.ops.object.mode_set(..) seems to be not have changed in 5.0…

Didn’t looked too much into this… so this crashed evee with only this line ???

Okay… funny thing: in 5.0 this does not work in the Text Editor and a new text file but it works in Python Console ??? :question:

You could have a bmesh without going into Edit mode…

bmNavMesh = bmesh.new()
bmNavMesh.from_mesh(ob_for_convert.data)

#......

bmNavMesh.to_mesh(ob_for_convert.data)

Thank you, I think I may have corrupted something in blender with another plugin because after restarting Blender bpy.ops.object.mode_set(mode=‘EDIT’) worked without any issue.

Gonna look deeper into what I did to break Blender.

Really? Thank you, I just tried this and it worked without issue.