# Python viewplane

I have a question on getting the mouse coordinates (in 3d space) when I click in the 3d view.

I have a draw handler in a modal operator (POST_VIEW) and I want to get the mouse cursor x, y vertex and the 3rd vertex should be on the current viewplane.

Do you have a Python example?

• See the Text Editor > Templates > Python > Operator Modal Draw template. – batFINGER Dec 15 '18 at 14:24

bpy_extras.view3d_utils.region_2d_to_location_3d

Return a 3d location from the region relative 2d coords, aligned with depth_location.

Here is the code:

from bpy_extras.view3d_utils import region_2d_to_location_3d
...
x, y = event.mouse_region_x, event.mouse_region_y
region = context.region
rv3d = context.space_data.region_3d

# this is the vector
loc = region_2d_to_location_3d(region, rv3d, (x, y), (0, 0, 0))