Fix T55991: Python ignores scene switch argument

This commit is contained in:
Campbell Barton 2018-07-27 16:49:41 +10:00
parent 98c8094e3a
commit 3e2dfc6db8
Notes: blender-bot 2023-02-14 19:27:44 +01:00
Referenced by issue blender/blender-addons#55991, When switching scenes using "-S" argument in command line, scripts called by "--python-text" do not get correct scene context
1 changed files with 12 additions and 0 deletions

View File

@ -60,6 +60,8 @@
#include "BKE_sound.h"
#include "BKE_image.h"
#include "DNA_screen_types.h"
#include "DEG_depsgraph.h"
#ifdef WITH_FFMPEG
@ -1588,6 +1590,16 @@ static int arg_handle_scene_set(int argc, const char **argv, void *data)
Scene *scene = BKE_scene_set_name(CTX_data_main(C), argv[1]);
if (scene) {
CTX_data_scene_set(C, scene);
/* Set the scene of the first window, see: T55991,
* otherwise scrips that run later won't get this scene back from the context. */
wmWindow *win = CTX_wm_window(C);
if (win == NULL) {
win = CTX_wm_manager(C)->windows.first;
}
if (win != NULL) {
win->screen->scene = scene;
}
}
return 1;
}