Skip to main content
simpler solution lol
Source Link
Harry McKenzie
  • 14.5k
  • 11
  • 34
  • 74

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.

enter image description here

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
):
    viewcurrent_location = bpyarea.contextspaces.space_data

current_location = viewactive.region_3d.view_matrix.inverted().translation
 
print("Location of Current View:", current_location)
bpy.context.scene.cursor.location = current_location

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.

enter image description here

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

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.

enter image description here

import bpy

area = next(area for area in bpy.context.window.screen.areas if area.type == 'VIEW_3D')
current_location = area.spaces.active.region_3d.view_matrix.inverted().translation
print("Location of Current View:", current_location)
bpy.context.scene.cursor.location = current_location
Source Link
Harry McKenzie
  • 14.5k
  • 11
  • 34
  • 74

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.

enter image description here

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