I try to enter edit mode via python after setting up my scene. This causes blender to crash. It seems to be reproducible with a new instance of blender 3.4.1. If I run this script in a new project, it crashes on the second to last line. Basically I want to select a subset of the faces of the monkey, but I first have to enter edit mode, I guess. How can I achieve that and avoid the crash?
# select monkey
import bpy
import bmesh
import mathutils
import numpy as np
bpy.ops.object.select_all(action='DESELECT')
try:
bpy.ops.object.mode_set(mode='OBJECT')
except:
pass
if "Suzanne" not in bpy.data.objects:
bpy.ops.mesh.primitive_monkey_add()
if "Camera" not in bpy.data.objects:
bpy.ops.object.camera_add()
cam = bpy.data.objects["Camera"]
model = bpy.data.objects["Suzanne"]
model.select_set(True)
bpy.context.view_layer.objects.active = model
try:
bpy.context.scene.collection.objects.link(cam)
except:
pass
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.select_mode(type="FACE")