How do I switch main screens through GDScript plugin?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GooglyCoffeeMeat

I’ve recently been trying to make plugins and I made a custom main screen (like 2D, 3D, Script). I want to know how to switch between screens through a script.

:bust_in_silhouette: Reply From: wombatstampede

As far as I know this would mean that you have to “mess” with the Editor itself. I think Zylann did some plugin which lets you view/debug the node structure of the Godot GUI. Perhaps that will help you to identify the nodes to target.

Be aware that this is basically hacking and there’s no guarantee that the nodes will stay the same in newer Godot versions.

I once did some plugin code to close a scene tab. I don’t know if it still works though. Just for an example:

func close_scene_tab(scenename):
	var res=findSceneTab(dock.get_tree().root,scenename.get_basename())
	if res!=null:
		print("closing scene tab: "+scenename)
		res["node"].emit_signal("tab_close",res["ix"])

#scenename without .scn/.tscn
func findSceneTab(node,scenename,spaces=""):
	var res=null
	
	if node is Tabs:
		print (node.get_class()+": "+node.get_name())
		for i in range(0,node.get_tab_count()):
			print ("Tab "+String(i)+"/"+String(node.get_tab_count())+":"+node.get_tab_title(i))
			if node.get_tab_title(i)==scenename:
				return {"node":node, "ix":i}
	
	#print (node.get_name())
	for N in node.get_children():
		res=findSceneTab(N,scenename,spaces+" ")
		if res!=null:
			return res
			
	return null

Sorry, I forgot to tell what “dock” is. It is a little scene file from the plugin:

func _enter_tree():
	# When this plugin node enters tree, add the custom type

	dock = preload("res://addons/MaterialMigrateG3/MaterialMigrate.scn").instance()

wombatstampede | 2019-10-08 15:44

:bust_in_silhouette: Reply From: mechPenSketch

On the EditorPlugin, call:

get_editor_interface().set_main_screen_editor(str)

Where str, a String, is the name of the main screen you want to switch to.