I guess what I'm asking is a bit uncommon, but I'm making an addon and, despite having found a way to position and rotate the Editor's 3D viewport camera, all via scripting, changes will rollback instantly when camera is moved manually with the mouse, returning to pre-scripted position and rotation.

My intention is to autofocus custom nodes on 3D space whenever they are selected on the Scene tab to speed up the editting workflow of my game. I know if can be done pressing "F" with the mouse over the viewport itself, but it would be nice to be autofocused just clicking on the tree.

This is what I have inside my addon script:

func on_selection_changed(): # called from editor's signal triggering
var nodes = EditorInterface.get_selection().get_selected_nodes()
if nodes.size() == 1:
var node = nodes[0]
var pos = node.position
EditorInterface.set_main_screen_editor("3D")
var cam = EditorInterface.get_editor_viewport_3d().get_camera_3d()
cam.look_at_from_position(pos + Vector3(-3, 2, 2), pos, Vector3.UP)

So wrapping things up, that script works, but as I said, the camera goes back to its orginal position and rotation the moment I move it with the mouse, I guess something's happening under the hood, like godot's editor has some non exposed internal vars that don't get updated properly (like the camera's current focus target or something like that), as the camera object returned from get_camera_3d() is just a regular Camera3D Node, with no special properties or so.

I also tried to make things the other way around, trying to push the "F" keypress event through the editor's 3D viewport, but it does not seem to work either:

func on_selection_changed():
EditorInterface.get_editor_viewport_3d().set_process_unhandled_input(true)
var event = InputEventKey.new()
event.keycode = KEY_F
event.physical_keycode = KEY_F
event.pressed = true
print(EditorInterface.get_editor_viewport_3d().is_processing_unhandled_input())
EditorInterface.get_editor_viewport_3d().push_unhandled_input(event)
EditorInterface.get_editor_viewport_3d().set_process_unhandled_input(false)

Any clues? Thanks in advance.