0
$\begingroup$

I am trying to center the view to the mouse point in a Python modal operator. However, I just couldn't find the right operator in the API documentation.

https://docs.blender.org/api/current/bpy.ops.view3d.html

I found bpy.ops.view3d.view_selected() and using it like this

elif event.type in {'MIDDLEMOUSE'}:
    if event.alt:
        bpy.ops.view3d.view_selected()

does center on the selected object which is a similar operation but not exactly what I wanted. Basically I would like to perform the same operation Blender is calling when pressing ALT+MIDDLEMOUSE in the 3D viewport ("Center View to Mouse").

Anyone knows the right operator for this?

$\endgroup$
0
$\begingroup$

I found the solution:

bpy.ops.view3d.view_center_cursor()

See https://docs.blender.org/api/current/bpy.ops.view3d.html#bpy.ops.view3d.view_center_cursor

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.