In Blender/Python 2.8, I am trying to use knife project to cut a circle through a cube. I am attempting to automate a process I can do manually.
My code is below; the last line throws this error:
RuntimeError: Operator bpy.ops.mesh.knife_project.poll() expected a view3d region & editmesh
When I do the process manually, I set the view as front ortho (numpad=1) so that the circle cuts the cube correctly. My code leaves that out as I don't know how to do the equivalent of setting the view in python for the purposes of knife project; and I am unsure if emulating the numpad keystroke will solve the problem, anyway.
Thanks for whatever help you can offer!
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.curve.primitive_bezier_circle_add(radius=.25, enter_editmode=False, location=(0, 0, 0))
bpy.ops.transform.rotate(value=1.5708, orient_axis='X', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(True, False, False), mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
bpy.ops.transform.translate(value=(0, -2, 0), orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, True, False), mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
bpy.data.objects['Cube'].select_set(True)
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
bpy.ops.mesh.knife_project()
```