Accept non-existing files from the CLI

When a user tries to load a non-existing blend file from the CLI, the path
is set and Blender acts as if it is loaded. This allows the user to create
a new file by typing 'blender filename.blend' and then saving. This
behaviour is common in other tooling, such as vim and Mypaint.

Blender's current behaviour (print an error message and open the default
scene) doesn't make much sense. It ignores the filename passed on the CLI,
whereas with this patch that filename is actually remembered, and used when
saving.

Reviewers: campbellbarton, sergey, mont29
This commit is contained in:
Sybren A. Stüvel 2015-11-25 12:47:54 +01:00
parent e796581655
commit 6894fe3b7a
1 changed files with 8 additions and 2 deletions

View File

@ -1505,7 +1505,7 @@ static int load_file(int UNUSED(argc), const char **argv, void *data)
}
}
else {
/* failed to load file, stop processing arguments */
/* failed to load file, stop processing arguments if running in background mode */
if (G.background) {
/* Set is_break if running in the background mode so
* blender will return non-zero exit code which then
@ -1513,8 +1513,14 @@ static int load_file(int UNUSED(argc), const char **argv, void *data)
* good or bad things are.
*/
G.is_break = true;
return -1;
}
return -1;
/* Just pretend a file was loaded, so the user can press Save and it'll save at the filename from the CLI. */
BLI_strncpy(G.main->name, filename, FILE_MAX);
G.relbase_valid = true;
G.save_over = true;
printf("... opened default scene instead; saving will write to %s\n", filename);
}
G.file_loaded = 1;