[Bf-blender-cvs] [6894fe3] master: Accept non-existing files from the CLI

Sybren A. Stüvel noreply at git.blender.org
Wed Nov 25 13:59:49 CET 2015


Commit: 6894fe3b7a200c4eae8ad980c3dcafe54e52393f
Author: Sybren A. Stüvel
Date:   Wed Nov 25 12:47:54 2015 +0100
Branches: master
https://developer.blender.org/rB6894fe3b7a200c4eae8ad980c3dcafe54e52393f

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

===================================================================

M	source/creator/creator.c

===================================================================

diff --git a/source/creator/creator.c b/source/creator/creator.c
index c6203b6..f7dd0aa 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -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;




More information about the Bf-blender-cvs mailing list