The EditorInterface class has a method called “edit_node” that does just what I was looking for (The tool script has to have access to that class to use that method).
this is possible thru plugins
in EditorPlugin you can get EditorInterface
like so - plugin.get_editor_interface().get_selection()
now you can use methods from here:
for example if you want to select root node of the scene:
just pass to add_node method nodes that you want to be selected
here is my own list of functions to work with nodes in editor (Godot 3.5)
# way to get editor scene selected nodes
# works only with tool scripts
static func get_selected_nodes(plugin:EditorPlugin)->Array:
return plugin.get_editor_interface().get_selection().get_selected_nodes()
# for single node
static func get_selected_node(plugin:EditorPlugin)->Node:
var selected = get_selected_nodes(plugin)
if not selected.empty():
# Always pick first node in selection
return selected[0]
return null
# selects desired node in editor
static func select_editor_node(plugin:EditorPlugin, node:Node):
plugin.get_editor_interface().get_selection().add_node(node)
# getting edited scene
static func get_edited_scene_root(plugin:EditorPlugin):
return plugin.get_editor_interface().get_edited_scene_root()