Load specific scene in editor

Is there a way that you can load / unload a scene from the editor script? I want to automate a task of ensuring a set of scenes are constructed correctly, but I can’t find any API calls for doing a modify - save - load sequence in the editor.

Ideally, I’d do something like:

foreach(var scene in myLevels)
{
//Save any changes in currently loaded scene
//Load the scene
//Find objects I want to configure and modify them
}

Is this possible to automate?

EditorApplication.SaveCurrentSceneIfUserWantsTo();
and
EditorApplication.OpenScene(scenePath);
are obsolete!

You should use EditorSceneManager. For example:

using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
    
public class MySceneLoader : MonoBehaviour {

    [MenuItem ("Scenes/Open Main Scene")]
    static void OpenMainScene() {
        EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
        EditorSceneManager.OpenScene("Assets/Scenes/main.unity");
    }
}

Don’t forget to put MySceneLoader.cs into Editor folder.

EditorApplication.SaveCurrentSceneIfUserWantsTo();
EditorApplication.OpenScene(scenePath);