mouse coordinate to view 3d coordinate

some one can tell me if there is a way to convert the mouse_region_x/y coordinates to the view 3d euler(cartesian) value?

cursorLoc = bpy.context.scene.cursor_location
print ("
Cursor Location:", cursorLoc

salutations

this can be used with modal operator? for example: i want dinamically move the cursor by holding the right mouse and each fixed step(i.e 30 u) translate the extruded face, is possible?

Have a look at the modal operator templates. These are in the templates menu of the text editor. The simple modal operator moves the active objects x location with the mouse.

solved in part, i found the function in bpy_extras.view3d_utils.region_2d_to_location_3d. but i need an operator:
if you check the documentation there is a thing called depth_location,"(3d vector) – the returned vectors depth is aligned with this since there is no defined depth with a 2d region input". and i don’t know what exactly is, and how to find the relative operator that return the depth location of the view.

there is some on who can help me?

Use the methods in an operator.
Run this in the 3d view, eg call from the search for operator menu, and the context object sticks to the mouse



import bpy
from bpy_extras.view3d_utils import region_2d_to_vector_3d, region_2d_to_location_3d


class ModalTimerOperator(bpy.types.Operator):
    '''Operator which runs its self from a timer.'''
    bl_idname = "wm.modal_timer_operator"
    bl_label = "Modal Timer Operator"

    _timer = None

    def modal(self, context, event):
        if event.type == 'ESC':
            return self.cancel(context)

        if event.type == 'TIMER':
            coord = event.mouse_region_x, event.mouse_region_y
            region = context.region
            rv3d = context.space_data.region_3d
            vec = region_2d_to_vector_3d(region, rv3d, coord)
            loc = region_2d_to_location_3d(region, rv3d, coord, vec)
            # change theme color, silly!
            context.object.location = loc

        return {'PASS_THROUGH'}

    def execute(self, context):
        context.window_manager.modal_handler_add(self)
        self._timer = context.window_manager.event_timer_add(0.1, context.window)
        return {'RUNNING_MODAL'}

    def cancel(self, context):
        context.window_manager.event_timer_remove(self._timer)
        return {'CANCELLED'}


def register():
    bpy.utils.register_class(ModalTimerOperator)


def unregister():
    bpy.utils.unregister_class(ModalTimerOperator)


if __name__ == "__main__":
    register()

    # test call
    #bpy.ops.wm.modal_timer_operator()  #needs to run from the 3d view

Thank a lot!!! this is what i’m looking for:D , i’ll mention your name in my script if want. yeah!

p.s i don’t understand how timer works.