Creating a root in scene using editor plugin

Godot Version



my Editor Plugin creates objects in scene like this:

var Scene = EditorInterface.get_edited_scene_root()
var object=
Scene .add_child(object)

in godot editor, clicking on scene-> new scene creates an empty scene with 4 options:
2D Scene, 3D Scene, User Interface and Other Node.
if there is an empty scene and we attempt to create an object in editor plugin using my code from above we get this error:
“res://addons/makeObject/ - Attempt to call function ‘add_child’ in base ‘null instance’ on a null instance.”
how do I create an empty root in the empty scene to avoid this error? basically I want the same thing that happens when I click on the “3D Scene” option of a new scene.
I have tried this without success:

var Scene = EditorInterface.get_edited_scene_root()
Scene =
var object=
Scene .add_child(object)
1 Like

As far as I know that functionality is not exposed to scripting. The only thing I can think of is to create a PackedScene, save it and open it with EditorInterface.open_scene_from_path()