Try the following script. When you execute it in the Text Editor
, it will set the 3D Cursor
at the center of the position of your current view in the 3D Viewport. Notice that after I execute the script, I slightly zoom out so you can see the position of the 3D Cursor where previously the view of 3D Viewport was located at.
import bpy
area = next(area for area in bpy.context.window.screen.areas if area.type == 'VIEW_3D')
with bpy.context.temp_override(
window=bpy.context.window,
area=area,
region=next(region for region in area.regions if region.type == 'WINDOW'),
screen=bpy.context.window.screen
):
view = bpy.context.space_data
current_location = view.region_3d.view_matrix.inverted().translation
print("Location of Current View:", current_location)
bpy.context.scene.cursor.location = current_location