2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * ***** END GPL LICENSE BLOCK *****
21 /** \file creator/creator_args.c
25 #ifndef WITH_PYTHON_MODULE
31 #include "MEM_guardedalloc.h"
34 # include "BLI_winstuff.h"
38 #include "BLI_threads.h"
39 #include "BLI_utildefines.h"
40 #include "BLI_listbase.h"
41 #include "BLI_string.h"
42 #include "BLI_string_utf8.h"
43 #include "BLI_path_util.h"
44 #include "BLI_fileops.h"
45 #include "BLI_mempool.h"
47 #include "BKE_blender_version.h"
48 #include "BKE_context.h"
50 #include "BKE_global.h"
51 #include "BKE_library.h"
53 #include "BKE_scene.h"
54 #include "BKE_report.h"
55 #include "BKE_sound.h"
56 #include "BKE_image.h"
59 #include "IMB_imbuf.h"
63 #include "BPY_extern.h"
66 #include "RE_engine.h"
67 #include "RE_pipeline.h"
69 #include "ED_datafiles.h"
73 #include "GPU_basic_shader.h"
75 #include "GPU_extensions.h"
77 /* for passing information between creator and gameengine */
78 #ifdef WITH_GAMEENGINE
79 # include "BL_System.h"
81 # define SYS_SystemHandle int
85 # include "libmv-capi.h"
88 #ifdef WITH_CYCLES_LOGGING
92 #include "creator_intern.h" /* own include */
95 /* -------------------------------------------------------------------- */
97 /** \name Utility String Parsing
100 static bool parse_int_relative(
101 const char *str, const char *str_end_test, int pos, int neg,
102 int *r_value, const char **r_err_msg)
104 char *str_end = NULL;
111 value = pos + strtol(str + 1, &str_end, 10);
114 value = (neg - strtol(str + 1, &str_end, 10)) + 1;
117 value = strtol(str, &str_end, 10);
122 if (*str_end != '\0' && (str_end != str_end_test)) {
123 static const char *msg = "not a number";
127 else if ((errno == ERANGE) || ((value < INT_MIN || value > INT_MAX))) {
128 static const char *msg = "exceeds range";
133 *r_value = (int)value;
138 static const char *parse_int_range_sep_search(const char *str, const char *str_end_test)
140 const char *str_end_range = NULL;
142 str_end_range = memchr(str, '.', (str_end_test - str) - 1);
143 if (str_end_range && (str_end_range[1] != '.')) {
144 str_end_range = NULL;
148 str_end_range = strstr(str, "..");
149 if (str_end_range && (str_end_range[2] == '\0')) {
150 str_end_range = NULL;
153 return str_end_range;
157 * Parse a number as a range, eg: `1..4`.
159 * The \a str_end_range argument is a result of #parse_int_range_sep_search.
161 static bool parse_int_range_relative(
162 const char *str, const char *str_end_range, const char *str_end_test, int pos, int neg,
163 int r_value_range[2], const char **r_err_msg)
165 if (parse_int_relative(str, str_end_range, pos, neg, &r_value_range[0], r_err_msg) &&
166 parse_int_relative(str_end_range + 2, str_end_test, pos, neg, &r_value_range[1], r_err_msg))
175 static bool parse_int_relative_clamp(
176 const char *str, const char *str_end_test, int pos, int neg, int min, int max,
177 int *r_value, const char **r_err_msg)
179 if (parse_int_relative(str, str_end_test, pos, neg, r_value, r_err_msg)) {
180 CLAMP(*r_value, min, max);
188 static bool parse_int_range_relative_clamp(
189 const char *str, const char *str_end_range, const char *str_end_test, int pos, int neg, int min, int max,
190 int r_value_range[2], const char **r_err_msg)
192 if (parse_int_range_relative(str, str_end_range, str_end_test, pos, neg, r_value_range, r_err_msg)) {
193 CLAMP(r_value_range[0], min, max);
194 CLAMP(r_value_range[1], min, max);
203 * No clamping, fails with any number outside the range.
205 static bool parse_int_strict_range(
206 const char *str, const char *str_end_test, const int min, const int max,
207 int *r_value, const char **r_err_msg)
209 char *str_end = NULL;
213 value = strtol(str, &str_end, 10);
215 if (*str_end != '\0' && (str_end != str_end_test)) {
216 static const char *msg = "not a number";
220 else if ((errno == ERANGE) || ((value < min || value > max))) {
221 static const char *msg = "exceeds range";
226 *r_value = (int)value;
231 static bool parse_int(
232 const char *str, const char *str_end_test,
233 int *r_value, const char **r_err_msg)
235 return parse_int_strict_range(str, str_end_test, INT_MIN, INT_MAX, r_value, r_err_msg);
238 static bool parse_int_clamp(
239 const char *str, const char *str_end_test, int min, int max,
240 int *r_value, const char **r_err_msg)
242 if (parse_int(str, str_end_test, r_value, r_err_msg)) {
243 CLAMP(*r_value, min, max);
253 * Version of #parse_int_relative_clamp
254 * that parses a comma separated list of numbers.
256 static int *parse_int_relative_clamp_n(
257 const char *str, int pos, int neg, int min, int max,
258 int *r_value_len, const char **r_err_msg)
260 const char sep = ',';
262 for (int i = 0; str[i]; i++) {
268 int *values = MEM_mallocN(sizeof(*values) * len, __func__);
271 const char *str_end = strchr(str, sep);
272 if ((*str == sep) || (*str == '\0')) {
273 static const char *msg = "incorrect comma use";
278 else if (parse_int_relative_clamp(str, str_end, pos, neg, min, max, &values[i], r_err_msg)) {
282 goto fail; /* error message already set */
285 if (str_end) { /* next */
288 else { /* finished */
304 * Version of #parse_int_relative_clamp & #parse_int_range_relative_clamp
305 * that parses a comma separated list of numbers.
307 * \note single values are evaluated as a range with matching start/end.
309 static int (*parse_int_range_relative_clamp_n(
310 const char *str, int pos, int neg, int min, int max,
311 int *r_value_len, const char **r_err_msg))[2]
313 const char sep = ',';
315 for (int i = 0; str[i]; i++) {
321 int (*values)[2] = MEM_mallocN(sizeof(*values) * len, __func__);
324 const char *str_end_range;
325 const char *str_end = strchr(str, sep);
326 if ((*str == sep) || (*str == '\0')) {
327 static const char *msg = "incorrect comma use";
331 else if ((str_end_range = parse_int_range_sep_search(str, str_end)) ?
332 parse_int_range_relative_clamp(str, str_end_range, str_end, pos, neg, min, max, values[i], r_err_msg) :
333 parse_int_relative_clamp(str, str_end, pos, neg, min, max, &values[i][0], r_err_msg))
335 if (str_end_range == NULL) {
336 values[i][1] = values[i][0];
341 goto fail; /* error message already set */
344 if (str_end) { /* next */
347 else { /* finished */
363 /* -------------------------------------------------------------------- */
367 /** \name Utilities Python Context Macro (#BPY_CTX_SETUP)
369 struct BlendePyContextStore {
376 static void arg_py_context_backup(
377 bContext *C, struct BlendePyContextStore *c_py,
378 const char *script_id)
380 c_py->wm = CTX_wm_manager(C);
381 c_py->scene = CTX_data_scene(C);
382 c_py->has_win = !BLI_listbase_is_empty(&c_py->wm->windows);
384 c_py->win = CTX_wm_window(C);
385 CTX_wm_window_set(C, c_py->wm->windows.first);
389 fprintf(stderr, "Python script \"%s\" "
390 "running with missing context data.\n", script_id);
394 static void arg_py_context_restore(
395 bContext *C, struct BlendePyContextStore *c_py)
397 /* script may load a file, check old data is valid before using */
399 if ((c_py->win == NULL) ||
400 ((BLI_findindex(&G.main->wm, c_py->wm) != -1) &&
401 (BLI_findindex(&c_py->wm->windows, c_py->win) != -1)))
403 CTX_wm_window_set(C, c_py->win);
407 if ((c_py->scene == NULL) ||
408 BLI_findindex(&G.main->scene, c_py->scene) != -1)
410 CTX_data_scene_set(C, c_py->scene);
414 /* macro for context setup/reset */
415 #define BPY_CTX_SETUP(_cmd) \
417 struct BlendePyContextStore py_c; \
418 arg_py_context_backup(C, &py_c, argv[1]); \
420 arg_py_context_restore(C, &py_c); \
423 #endif /* WITH_PYTHON */
428 /* -------------------------------------------------------------------- */
430 /** \name Handle Argument Callbacks
432 * \note Doc strings here are used in differently:
434 * - The `--help` message.
435 * - The man page (for Unix systems),
436 * see: `doc/manpage/blender.1.py`
437 * - Parsed and extracted for the manual,
438 * which converts our ad-hoc formatting to reStructuredText.
439 * see: https://docs.blender.org/manual/en/dev/advanced/command_line.html
443 static const char arg_handle_print_version_doc[] =
444 "\n\tPrint Blender version and exit"
446 static int arg_handle_print_version(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
448 printf(BLEND_VERSION_STRING_FMT);
450 printf("\tbuild date: %s\n", build_date);
451 printf("\tbuild time: %s\n", build_time);
452 printf("\tbuild commit date: %s\n", build_commit_date);
453 printf("\tbuild commit time: %s\n", build_commit_time);
454 printf("\tbuild hash: %s\n", build_hash);
455 printf("\tbuild platform: %s\n", build_platform);
456 printf("\tbuild type: %s\n", build_type);
457 printf("\tbuild c flags: %s\n", build_cflags);
458 printf("\tbuild c++ flags: %s\n", build_cxxflags);
459 printf("\tbuild link flags: %s\n", build_linkflags);
460 printf("\tbuild system: %s\n", build_system);
467 static const char arg_handle_print_help_doc[] =
468 "\n\tPrint this help text and exit"
470 static const char arg_handle_print_help_doc_win32[] =
471 "\n\tPrint this help text and exit (windows only)"
473 static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), void *data)
475 bArgs *ba = (bArgs *)data;
477 printf(BLEND_VERSION_STRING_FMT);
478 printf("Usage: blender [args ...] [file] [args ...]\n\n");
480 printf("Render Options:\n");
481 BLI_argsPrintArgDoc(ba, "--background");
482 BLI_argsPrintArgDoc(ba, "--render-anim");
483 BLI_argsPrintArgDoc(ba, "--scene");
484 BLI_argsPrintArgDoc(ba, "--render-frame");
485 BLI_argsPrintArgDoc(ba, "--frame-start");
486 BLI_argsPrintArgDoc(ba, "--frame-end");
487 BLI_argsPrintArgDoc(ba, "--frame-jump");
488 BLI_argsPrintArgDoc(ba, "--render-output");
489 BLI_argsPrintArgDoc(ba, "--engine");
490 BLI_argsPrintArgDoc(ba, "--threads");
493 printf("Format Options:\n");
494 BLI_argsPrintArgDoc(ba, "--render-format");
495 BLI_argsPrintArgDoc(ba, "--use-extension");
498 printf("Animation Playback Options:\n");
499 BLI_argsPrintArgDoc(ba, "-a");
502 printf("Window Options:\n");
503 BLI_argsPrintArgDoc(ba, "--window-border");
504 BLI_argsPrintArgDoc(ba, "--window-borderless");
505 BLI_argsPrintArgDoc(ba, "--window-geometry");
506 BLI_argsPrintArgDoc(ba, "--start-console");
507 BLI_argsPrintArgDoc(ba, "--no-native-pixels");
511 printf("Game Engine Specific Options:\n");
512 BLI_argsPrintArgDoc(ba, "-g");
515 printf("Python Options:\n");
516 BLI_argsPrintArgDoc(ba, "--enable-autoexec");
517 BLI_argsPrintArgDoc(ba, "--disable-autoexec");
521 BLI_argsPrintArgDoc(ba, "--python");
522 BLI_argsPrintArgDoc(ba, "--python-text");
523 BLI_argsPrintArgDoc(ba, "--python-expr");
524 BLI_argsPrintArgDoc(ba, "--python-console");
525 BLI_argsPrintArgDoc(ba, "--python-exit-code");
526 BLI_argsPrintArgDoc(ba, "--addons");
530 printf("Debug Options:\n");
531 BLI_argsPrintArgDoc(ba, "--debug");
532 BLI_argsPrintArgDoc(ba, "--debug-value");
535 BLI_argsPrintArgDoc(ba, "--debug-events");
537 BLI_argsPrintArgDoc(ba, "--debug-ffmpeg");
539 BLI_argsPrintArgDoc(ba, "--debug-handlers");
541 BLI_argsPrintArgDoc(ba, "--debug-libmv");
543 #ifdef WITH_CYCLES_LOGGING
544 BLI_argsPrintArgDoc(ba, "--debug-cycles");
546 BLI_argsPrintArgDoc(ba, "--debug-memory");
547 BLI_argsPrintArgDoc(ba, "--debug-jobs");
548 BLI_argsPrintArgDoc(ba, "--debug-python");
549 BLI_argsPrintArgDoc(ba, "--debug-depsgraph");
550 BLI_argsPrintArgDoc(ba, "--debug-depsgraph-no-threads");
552 BLI_argsPrintArgDoc(ba, "--debug-gpumem");
553 BLI_argsPrintArgDoc(ba, "--debug-wm");
554 BLI_argsPrintArgDoc(ba, "--debug-all");
555 BLI_argsPrintArgDoc(ba, "--debug-io");
558 BLI_argsPrintArgDoc(ba, "--debug-fpe");
559 BLI_argsPrintArgDoc(ba, "--disable-crash-handler");
562 printf("Misc Options:\n");
563 BLI_argsPrintArgDoc(ba, "--factory-startup");
565 BLI_argsPrintArgDoc(ba, "--env-system-datafiles");
566 BLI_argsPrintArgDoc(ba, "--env-system-scripts");
567 BLI_argsPrintArgDoc(ba, "--env-system-python");
569 BLI_argsPrintArgDoc(ba, "-nojoystick");
570 BLI_argsPrintArgDoc(ba, "-noglsl");
571 BLI_argsPrintArgDoc(ba, "-noaudio");
572 BLI_argsPrintArgDoc(ba, "-setaudio");
576 BLI_argsPrintArgDoc(ba, "--help");
579 BLI_argsPrintArgDoc(ba, "-R");
580 BLI_argsPrintArgDoc(ba, "-r");
582 BLI_argsPrintArgDoc(ba, "--version");
584 BLI_argsPrintArgDoc(ba, "--");
587 printf("Experimental Features:\n");
588 BLI_argsPrintArgDoc(ba, "--enable-new-basic-shader-glsl");
590 /* Other options _must_ be last (anything not handled will show here) */
592 printf("Other Options:\n");
593 BLI_argsPrintOtherDoc(ba);
596 printf("Argument Parsing:\n");
597 printf("\tArguments must be separated by white space, eg:\n");
598 printf("\t# blender -ba test.blend\n");
599 printf("\t...will ignore the 'a'\n");
600 printf("\t# blender -b test.blend -f8\n");
601 printf("\t...will ignore '8' because there is no space between the '-f' and the frame value\n\n");
603 printf("Argument Order:\n");
604 printf("\tArguments are executed in the order they are given. eg:\n");
605 printf("\t# blender --background test.blend --render-frame 1 --render-output '/tmp'\n");
606 printf("\t...will not render to '/tmp' because '--render-frame 1' renders before the output path is set\n");
607 printf("\t# blender --background --render-output /tmp test.blend --render-frame 1\n");
608 printf("\t...will not render to '/tmp' because loading the blend-file overwrites the render output that was set\n");
609 printf("\t# blender --background test.blend --render-output /tmp --render-frame 1\n");
610 printf("\t...works as expected.\n\n");
612 printf("Environment Variables:\n");
613 printf(" $BLENDER_USER_CONFIG Directory for user configuration files.\n");
614 printf(" $BLENDER_USER_SCRIPTS Directory for user scripts.\n");
615 printf(" $BLENDER_SYSTEM_SCRIPTS Directory for system wide scripts.\n");
616 printf(" $BLENDER_USER_DATAFILES Directory for user data files (icons, translations, ..).\n");
617 printf(" $BLENDER_SYSTEM_DATAFILES Directory for system wide data files.\n");
618 printf(" $BLENDER_SYSTEM_PYTHON Directory for system python libraries.\n");
620 printf(" $TEMP Store temporary files here.\n");
622 printf(" $TMP or $TMPDIR Store temporary files here.\n");
625 printf(" $SDL_AUDIODRIVER LibSDL audio driver - alsa, esd, dma.\n");
627 printf(" $PYTHONHOME Path to the python directory, eg. /usr/lib/python.\n\n");
634 static const char arg_handle_arguments_end_doc[] =
635 "\n\tEnds option processing, following arguments passed unchanged. Access via Python's 'sys.argv'"
637 static int arg_handle_arguments_end(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
642 /* only to give help message */
643 #ifndef WITH_PYTHON_SECURITY /* default */
644 # define PY_ENABLE_AUTO ", (default)"
645 # define PY_DISABLE_AUTO ""
647 # define PY_ENABLE_AUTO ""
648 # define PY_DISABLE_AUTO ", (compiled as non-standard default)"
651 static const char arg_handle_python_set_doc_enable[] =
652 "\n\tEnable automatic Python script execution" PY_ENABLE_AUTO
654 static const char arg_handle_python_set_doc_disable[] =
655 "\n\tDisable automatic Python script execution (pydrivers & startup scripts)" PY_DISABLE_AUTO
657 #undef PY_ENABLE_AUTO
658 #undef PY_DISABLE_AUTO
660 static int arg_handle_python_set(int UNUSED(argc), const char **UNUSED(argv), void *data)
663 G.f |= G_SCRIPT_AUTOEXEC;
666 G.f &= ~G_SCRIPT_AUTOEXEC;
668 G.f |= G_SCRIPT_OVERRIDE_PREF;
672 static const char arg_handle_crash_handler_disable_doc[] =
673 "\n\tDisable the crash handler"
675 static int arg_handle_crash_handler_disable(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
677 app_state.signal.use_crash_handler = false;
681 static const char arg_handle_abort_handler_disable_doc[] =
682 "\n\tDisable the abort handler"
684 static int arg_handle_abort_handler_disable(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
686 app_state.signal.use_abort_handler = false;
690 static const char arg_handle_background_mode_set_doc[] =
691 "\n\tRun in background (often used for UI-less rendering)"
693 static int arg_handle_background_mode_set(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
699 static const char arg_handle_debug_mode_set_doc[] =
701 "\tTurn debugging on\n"
703 "\t* Enables memory error detection\n"
704 "\t* Disables mouse grab (to interact with a debugger in some cases)\n"
705 "\t* Keeps Python's 'sys.stdin' rather than setting it to None"
707 static int arg_handle_debug_mode_set(int UNUSED(argc), const char **UNUSED(argv), void *data)
709 G.debug |= G_DEBUG; /* std output printf's */
710 printf(BLEND_VERSION_STRING_FMT);
711 MEM_set_memory_debug();
713 BLI_mempool_set_memory_debug();
716 #ifdef WITH_BUILDINFO
717 printf("Build: %s %s %s %s\n", build_date, build_time, build_platform, build_type);
725 static const char arg_handle_debug_mode_generic_set_doc_ffmpeg[] =
726 "\n\tEnable debug messages from FFmpeg library";
728 #ifdef WITH_FREESTYLE
729 static const char arg_handle_debug_mode_generic_set_doc_freestyle[] =
730 "\n\tEnable debug messages for FreeStyle";
732 static const char arg_handle_debug_mode_generic_set_doc_python[] =
733 "\n\tEnable debug messages for Python";
734 static const char arg_handle_debug_mode_generic_set_doc_events[] =
735 "\n\tEnable debug messages for the event system";
736 static const char arg_handle_debug_mode_generic_set_doc_handlers[] =
737 "\n\tEnable debug messages for event handling";
738 static const char arg_handle_debug_mode_generic_set_doc_wm[] =
739 "\n\tEnable debug messages for the window manager, also prints every operator call";
740 static const char arg_handle_debug_mode_generic_set_doc_jobs[] =
741 "\n\tEnable time profiling for background jobs.";
742 static const char arg_handle_debug_mode_generic_set_doc_gpu[] =
743 "\n\tEnable gpu debug context and information for OpenGL 4.3+.";
744 static const char arg_handle_debug_mode_generic_set_doc_depsgraph[] =
745 "\n\tEnable debug messages from dependency graph";
746 static const char arg_handle_debug_mode_generic_set_doc_depsgraph_no_threads[] =
747 "\n\tSwitch dependency graph to a single threaded evaluation";
748 static const char arg_handle_debug_mode_generic_set_doc_gpumem[] =
749 "\n\tEnable GPU memory stats in status bar";
751 static int arg_handle_debug_mode_generic_set(int UNUSED(argc), const char **UNUSED(argv), void *data)
753 G.debug |= GET_INT_FROM_POINTER(data);
757 static const char arg_handle_debug_mode_io_doc[] =
758 "\n\tEnable debug messages for I/O (collada, ...)";
759 static int arg_handle_debug_mode_io(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
761 G.debug |= G_DEBUG_IO;
765 static const char arg_handle_debug_mode_all_doc[] =
766 "\n\tEnable all debug messages";
767 static int arg_handle_debug_mode_all(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
769 G.debug |= G_DEBUG_ALL;
771 libmv_startDebugLogging();
773 #ifdef WITH_CYCLES_LOGGING
774 CCL_start_debug_logging();
780 static const char arg_handle_debug_mode_libmv_doc[] =
781 "\n\tEnable debug messages from libmv library"
783 static int arg_handle_debug_mode_libmv(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
785 libmv_startDebugLogging();
791 #ifdef WITH_CYCLES_LOGGING
792 static const char arg_handle_debug_mode_cycles_doc[] =
793 "\n\tEnable debug messages from Cycles"
795 static int arg_handle_debug_mode_cycles(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
797 CCL_start_debug_logging();
802 static const char arg_handle_debug_mode_memory_set_doc[] =
803 "\n\tEnable fully guarded memory allocation and debugging"
805 static int arg_handle_debug_mode_memory_set(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
807 MEM_set_memory_debug();
811 static const char arg_handle_debug_value_set_doc[] =
813 "\tSet debug value of <value> on startup\n"
815 static int arg_handle_debug_value_set(int argc, const char **argv, void *UNUSED(data))
817 const char *arg_id = "--debug-value";
819 const char *err_msg = NULL;
821 if (!parse_int(argv[1], NULL, &value, &err_msg)) {
822 printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
826 G.debug_value = value;
831 printf("\nError: you must specify debug value to set.\n");
836 static const char arg_handle_debug_fpe_set_doc[] =
837 "\n\tEnable floating point exceptions"
839 static int arg_handle_debug_fpe_set(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
841 main_signal_setup_fpe();
845 static const char arg_handle_factory_startup_set_doc[] =
846 "\n\tSkip reading the " STRINGIFY(BLENDER_STARTUP_FILE) " in the users home directory"
848 static int arg_handle_factory_startup_set(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
850 G.factory_startup = 1;
854 static const char arg_handle_env_system_set_doc_datafiles[] =
855 "\n\tSet the "STRINGIFY_ARG (BLENDER_SYSTEM_DATAFILES)" environment variable";
856 static const char arg_handle_env_system_set_doc_scripts[] =
857 "\n\tSet the "STRINGIFY_ARG (BLENDER_SYSTEM_SCRIPTS)" environment variable";
858 static const char arg_handle_env_system_set_doc_python[] =
859 "\n\tSet the "STRINGIFY_ARG (BLENDER_SYSTEM_PYTHON)" environment variable";
861 static int arg_handle_env_system_set(int argc, const char **argv, void *UNUSED(data))
863 /* "--env-system-scripts" --> "BLENDER_SYSTEM_SCRIPTS" */
865 char env[64] = "BLENDER";
866 char *ch_dst = env + 7; /* skip BLENDER */
867 const char *ch_src = argv[0] + 5; /* skip --env */
870 printf("%s requires one argument\n", argv[0]);
874 for (; *ch_src; ch_src++, ch_dst++) {
875 *ch_dst = (*ch_src == '-') ? '_' : (*ch_src) - 32; /* toupper() */
879 BLI_setenv(env, argv[1]);
883 static const char arg_handle_playback_mode_doc[] =
884 "<options> <file(s)>\n"
885 "\tPlayback <file(s)>, only operates this way when not running in background.\n"
886 "\t\t-p <sx> <sy>\tOpen with lower left corner at <sx>, <sy>\n"
887 "\t\t-m\t\tRead from disk (Do not buffer)\n"
888 "\t\t-f <fps> <fps-base>\t\tSpecify FPS to start with\n"
889 "\t\t-j <frame>\tSet frame step to <frame>\n"
890 "\t\t-s <frame>\tPlay from <frame>\n"
891 "\t\t-e <frame>\tPlay until <frame>"
893 static int arg_handle_playback_mode(int argc, const char **argv, void *UNUSED(data))
895 /* not if -b was given first */
896 if (G.background == 0) {
898 /* Setup FFmpeg with current debug flags. */
902 WM_main_playanim(argc, argv); /* not the same argc and argv as before */
903 exit(0); /* 2.4x didn't do this */
909 static const char arg_handle_window_geometry_doc[] =
910 "<sx> <sy> <w> <h>\n"
911 "\tOpen with lower left corner at <sx>, <sy> and width and height as <w>, <h>"
913 static int arg_handle_window_geometry(int argc, const char **argv, void *UNUSED(data))
915 const char *arg_id = "-p / --window-geometry";
919 fprintf(stderr, "Error: requires four arguments '%s'\n", arg_id);
923 for (i = 0; i < 4; i++) {
924 const char *err_msg = NULL;
925 if (!parse_int(argv[i + 1], NULL, ¶ms[i], &err_msg)) {
926 printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
931 WM_init_state_size_set(UNPACK4(params));
936 static const char arg_handle_native_pixels_set_doc[] =
937 "\n\tDo not use native pixel size, for high resolution displays (MacBook 'Retina')"
939 static int arg_handle_native_pixels_set(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
941 WM_init_native_pixels(false);
945 static const char arg_handle_with_borders_doc[] =
946 "\n\tForce opening with borders"
948 static int arg_handle_with_borders(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
950 WM_init_state_normal_set();
954 static const char arg_handle_without_borders_doc[] =
955 "\n\tForce opening without borders"
957 static int arg_handle_without_borders(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
959 WM_init_state_fullscreen_set();
963 extern bool wm_start_with_console; /* wm_init_exit.c */
965 static const char arg_handle_start_with_console_doc[] =
966 "\n\tStart with the console window open (ignored if -b is set), (Windows only)"
968 static int arg_handle_start_with_console(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
970 wm_start_with_console = true;
974 static const char arg_handle_register_extension_doc[] =
975 "\n\tRegister blend-file extension, then exit (Windows only)"
977 static const char arg_handle_register_extension_doc_silent[] =
978 "\n\tSilently register blend-file extension, then exit (Windows only)"
980 static int arg_handle_register_extension(int UNUSED(argc), const char **UNUSED(argv), void *data)
985 RegisterBlendExtension();
987 (void)data; /* unused */
992 static const char arg_handle_joystick_disable_doc[] =
993 "\n\tDisable joystick support"
995 static int arg_handle_joystick_disable(int UNUSED(argc), const char **UNUSED(argv), void *data)
997 #ifndef WITH_GAMEENGINE
1000 SYS_SystemHandle *syshandle = data;
1003 * don't initialize joysticks if user doesn't want to use joysticks
1004 * failed joystick initialization delays over 5 seconds, before game engine start
1006 SYS_WriteCommandLineInt(*syshandle, "nojoystick", 1);
1007 if (G.debug & G_DEBUG) printf("disabling nojoystick\n");
1013 static const char arg_handle_glsl_disable_doc[] =
1014 "\n\tDisable GLSL shading"
1016 static int arg_handle_glsl_disable(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
1018 GPU_extensions_disable();
1022 static const char arg_handle_audio_disable_doc[] =
1023 "\n\tForce sound system to None"
1025 static int arg_handle_audio_disable(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
1027 BKE_sound_force_device("Null");
1031 static const char arg_handle_audio_set_doc[] =
1032 "\n\tForce sound system to a specific device\n\tNULL SDL OPENAL JACK"
1034 static int arg_handle_audio_set(int argc, const char **argv, void *UNUSED(data))
1037 fprintf(stderr, "-setaudio require one argument\n");
1041 BKE_sound_force_device(argv[1]);
1045 static const char arg_handle_output_set_doc[] =
1047 "\tSet the render path and file name.\n"
1048 "\tUse '//' at the start of the path to render relative to the blend-file.\n"
1050 "\tThe '#' characters are replaced by the frame number, and used to define zero padding.\n"
1052 "\t* 'ani_##_test.png' becomes 'ani_01_test.png'\n"
1053 "\t* 'test-######.png' becomes 'test-000001.png'\n"
1055 "\tWhen the filename does not contain '#', The suffix '####' is added to the filename.\n"
1057 "\tThe frame number will be added at the end of the filename, eg:\n"
1058 "\t# blender -b foobar.blend -o //render_ -F PNG -x 1 -a\n"
1059 "\t'//render_' becomes '//render_####', writing frames as '//render_0001.png'"
1061 static int arg_handle_output_set(int argc, const char **argv, void *data)
1065 Scene *scene = CTX_data_scene(C);
1067 BLI_strncpy(scene->r.pic, argv[1], sizeof(scene->r.pic));
1070 printf("\nError: no blend loaded. cannot use '-o / --render-output'.\n");
1075 printf("\nError: you must specify a path after '-o / --render-output'.\n");
1080 static const char arg_handle_engine_set_doc[] =
1082 "\tSpecify the render engine\n\tuse -E help to list available engines"
1084 static int arg_handle_engine_set(int argc, const char **argv, void *data)
1088 if (STREQ(argv[1], "help")) {
1089 RenderEngineType *type = NULL;
1090 printf("Blender Engine Listing:\n");
1091 for (type = R_engines.first; type; type = type->next) {
1092 printf("\t%s\n", type->idname);
1097 Scene *scene = CTX_data_scene(C);
1099 RenderData *rd = &scene->r;
1101 if (BLI_findstring(&R_engines, argv[1], offsetof(RenderEngineType, idname))) {
1102 BLI_strncpy_utf8(rd->engine, argv[1], sizeof(rd->engine));
1105 printf("\nError: engine not found '%s'\n", argv[1]);
1110 printf("\nError: no blend loaded. "
1111 "order the arguments so '-E / --engine ' is after a blend is loaded.\n");
1118 printf("\nEngine not specified, give 'help' for a list of available engines.\n");
1123 static const char arg_handle_image_type_set_doc[] =
1125 "\tSet the render format, Valid options are...\n"
1126 "\t\tTGA RAWTGA JPEG IRIS IRIZ\n"
1127 "\t\tAVIRAW AVIJPEG PNG BMP\n"
1128 "\t(formats that can be compiled into blender, not available on all systems)\n"
1129 "\t\tHDR TIFF EXR MULTILAYER MPEG FRAMESERVER QUICKTIME CINEON DPX DDS JP2"
1131 static int arg_handle_image_type_set(int argc, const char **argv, void *data)
1135 const char *imtype = argv[1];
1136 Scene *scene = CTX_data_scene(C);
1138 const char imtype_new = BKE_imtype_from_arg(imtype);
1140 if (imtype_new == R_IMF_IMTYPE_INVALID) {
1141 printf("\nError: Format from '-F / --render-format' not known or not compiled in this release.\n");
1144 scene->r.im_format.imtype = imtype_new;
1148 printf("\nError: no blend loaded. "
1149 "order the arguments so '-F / --render-format' is after the blend is loaded.\n");
1154 printf("\nError: you must specify a format after '-F / --render-foramt'.\n");
1159 static const char arg_handle_threads_set_doc[] =
1161 "\tUse amount of <threads> for rendering and other operations\n"
1162 "\t[1-" STRINGIFY(BLENDER_MAX_THREADS) "], 0 for systems processor count."
1164 static int arg_handle_threads_set(int argc, const char **argv, void *UNUSED(data))
1166 const char *arg_id = "-t / --threads";
1167 const int min = 0, max = BLENDER_MAX_THREADS;
1169 const char *err_msg = NULL;
1171 if (!parse_int_strict_range(argv[1], NULL, min, max, &threads, &err_msg)) {
1172 printf("\nError: %s '%s %s', expected number in [%d..%d].\n", err_msg, arg_id, argv[1], min, max);
1176 BLI_system_num_threads_override_set(threads);
1180 printf("\nError: you must specify a number of threads in [%d..%d] '%s'.\n", min, max, arg_id);
1185 static const char arg_handle_verbosity_set_doc[] =
1187 "\tSet logging verbosity level."
1189 static int arg_handle_verbosity_set(int argc, const char **argv, void *UNUSED(data))
1191 const char *arg_id = "--verbose";
1193 const char *err_msg = NULL;
1195 if (!parse_int(argv[1], NULL, &level, &err_msg)) {
1196 printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
1200 libmv_setLoggingVerbosity(level);
1201 #elif defined(WITH_CYCLES_LOGGING)
1202 CCL_logging_verbosity_set(level);
1210 printf("\nError: you must specify a verbosity level.\n");
1215 static const char arg_handle_extension_set_doc[] =
1217 "\tSet option to add the file extension to the end of the file"
1219 static int arg_handle_extension_set(int argc, const char **argv, void *data)
1223 Scene *scene = CTX_data_scene(C);
1225 if (argv[1][0] == '0') {
1226 scene->r.scemode &= ~R_EXTENSION;
1228 else if (argv[1][0] == '1') {
1229 scene->r.scemode |= R_EXTENSION;
1232 printf("\nError: Use '-x 1 / -x 0' To set the extension option or '--use-extension'\n");
1236 printf("\nError: no blend loaded. "
1237 "order the arguments so '-o ' is after '-x '.\n");
1242 printf("\nError: you must specify a path after '- '.\n");
1247 static const char arg_handle_ge_parameters_set_doc[] =
1248 "Game Engine specific options\n"
1249 "\t-g fixedtime\t\tRun on 50 hertz without dropping frames\n"
1250 "\t-g vertexarrays\t\tUse Vertex Arrays for rendering (usually faster)\n"
1251 "\t-g nomipmap\t\tNo Texture Mipmapping\n"
1252 "\t-g linearmipmap\t\tLinear Texture Mipmapping instead of Nearest (default)"
1254 static int arg_handle_ge_parameters_set(int argc, const char **argv, void *data)
1257 #ifdef WITH_GAMEENGINE
1258 SYS_SystemHandle syshandle = *(SYS_SystemHandle *)data;
1264 * gameengine parameters are automatically put into system
1265 * -g [paramname = value]
1266 * -g [boolparamname]
1269 * -g maxvertexarraysize = 512
1273 const char *paramname = argv[a];
1274 /* check for single value versus assignment */
1275 if (a + 1 < argc && (*(argv[a + 1]) == '=')) {
1280 #ifdef WITH_GAMEENGINE
1281 SYS_WriteCommandLineString(syshandle, paramname, argv[a]);
1285 printf("error: argument assignment (%s) without value.\n", paramname);
1288 /* name arg eaten */
1292 #ifdef WITH_GAMEENGINE
1293 SYS_WriteCommandLineInt(syshandle, argv[a], 1);
1296 if (STREQ(argv[a], "nomipmap")) {
1297 GPU_set_mipmap(0); //doMipMap = 0;
1300 if (STREQ(argv[a], "linearmipmap")) {
1302 GPU_set_linear_mipmap(1); //linearMipMap = 1;
1306 } /* if (*(argv[a + 1]) == '=') */
1312 static const char arg_handle_render_frame_doc[] =
1314 "\tRender frame <frame> and save it.\n"
1316 "\t* +<frame> start frame relative, -<frame> end frame relative.\n"
1317 "\t* A comma separated list of frames can also be used (no spaces).\n"
1318 "\t* A range of frames can be expressed using '..' seperator between the first and last frames (inclusive).\n"
1320 static int arg_handle_render_frame(int argc, const char **argv, void *data)
1322 const char *arg_id = "-f / --render-frame";
1324 Scene *scene = CTX_data_scene(C);
1326 Main *bmain = CTX_data_main(C);
1329 const char *err_msg = NULL;
1333 int (*frame_range_arr)[2], frames_range_len;
1334 if ((frame_range_arr = parse_int_range_relative_clamp_n(
1335 argv[1], scene->r.sfra, scene->r.efra, MINAFRAME, MAXFRAME,
1336 &frames_range_len, &err_msg)) == NULL)
1338 printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
1342 re = RE_NewRender(scene->id.name);
1343 BLI_begin_threaded_malloc();
1344 BKE_reports_init(&reports, RPT_STORE);
1346 RE_SetReports(re, &reports);
1347 for (int i = 0; i < frames_range_len; i++) {
1348 /* We could pass in frame ranges,
1349 * but prefer having exact behavior as passing in multiple frames */
1350 if ((frame_range_arr[i][0] <= frame_range_arr[i][1]) == 0) {
1351 printf("\nWarning: negative range ignored '%s %s'.\n", arg_id, argv[1]);
1354 for (int frame = frame_range_arr[i][0]; frame <= frame_range_arr[i][1]; frame++) {
1355 RE_BlenderAnim(re, bmain, scene, NULL, scene->lay, frame, frame, scene->r.frame_step);
1358 RE_SetReports(re, NULL);
1359 BKE_reports_clear(&reports);
1360 BLI_end_threaded_malloc();
1361 MEM_freeN(frame_range_arr);
1365 printf("\nError: frame number must follow '%s'.\n", arg_id);
1370 printf("\nError: no blend loaded. cannot use '%s'.\n", arg_id);
1375 static const char arg_handle_render_animation_doc[] =
1376 "\n\tRender frames from start to end (inclusive)"
1378 static int arg_handle_render_animation(int UNUSED(argc), const char **UNUSED(argv), void *data)
1381 Scene *scene = CTX_data_scene(C);
1383 Main *bmain = CTX_data_main(C);
1384 Render *re = RE_NewRender(scene->id.name);
1386 BLI_begin_threaded_malloc();
1387 BKE_reports_init(&reports, RPT_STORE);
1388 RE_SetReports(re, &reports);
1389 RE_BlenderAnim(re, bmain, scene, NULL, scene->lay, scene->r.sfra, scene->r.efra, scene->r.frame_step);
1390 RE_SetReports(re, NULL);
1391 BKE_reports_clear(&reports);
1392 BLI_end_threaded_malloc();
1395 printf("\nError: no blend loaded. cannot use '-a'.\n");
1400 static const char arg_handle_scene_set_doc[] =
1402 "\tSet the active scene <name> for rendering"
1404 static int arg_handle_scene_set(int argc, const char **argv, void *data)
1408 Scene *scene = BKE_scene_set_name(CTX_data_main(C), argv[1]);
1410 CTX_data_scene_set(C, scene);
1415 printf("\nError: Scene name must follow '-S / --scene'.\n");
1420 static const char arg_handle_frame_start_set_doc[] =
1422 "\tSet start to frame <frame>, supports +/- for relative frames too."
1424 static int arg_handle_frame_start_set(int argc, const char **argv, void *data)
1426 const char *arg_id = "-s / --frame-start";
1428 Scene *scene = CTX_data_scene(C);
1431 const char *err_msg = NULL;
1432 if (!parse_int_relative_clamp(
1433 argv[1], NULL, scene->r.sfra, scene->r.sfra - 1, MINAFRAME, MAXFRAME,
1434 &scene->r.sfra, &err_msg))
1436 printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
1441 printf("\nError: frame number must follow '%s'.\n", arg_id);
1446 printf("\nError: no blend loaded. cannot use '%s'.\n", arg_id);
1451 static const char arg_handle_frame_end_set_doc[] =
1453 "\tSet end to frame <frame>, supports +/- for relative frames too."
1455 static int arg_handle_frame_end_set(int argc, const char **argv, void *data)
1457 const char *arg_id = "-e / --frame-end";
1459 Scene *scene = CTX_data_scene(C);
1462 const char *err_msg = NULL;
1463 if (!parse_int_relative_clamp(
1464 argv[1], NULL, scene->r.efra, scene->r.efra - 1, MINAFRAME, MAXFRAME,
1465 &scene->r.efra, &err_msg))
1467 printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
1472 printf("\nError: frame number must follow '%s'.\n", arg_id);
1477 printf("\nError: no blend loaded. cannot use '%s'.\n", arg_id);
1482 static const char arg_handle_frame_skip_set_doc[] =
1484 "\tSet number of frames to step forward after each rendered frame"
1486 static int arg_handle_frame_skip_set(int argc, const char **argv, void *data)
1488 const char *arg_id = "-j / --frame-jump";
1490 Scene *scene = CTX_data_scene(C);
1493 const char *err_msg = NULL;
1494 if (!parse_int_clamp(argv[1], NULL, 1, MAXFRAME, &scene->r.frame_step, &err_msg)) {
1495 printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]);
1500 printf("\nError: number of frames to step must follow '%s'.\n", arg_id);
1505 printf("\nError: no blend loaded. cannot use '%s'.\n", arg_id);
1510 static const char arg_handle_python_file_run_doc[] =
1512 "\tRun the given Python script file"
1514 static int arg_handle_python_file_run(int argc, const char **argv, void *data)
1519 /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */
1521 /* Make the path absolute because its needed for relative linked blends to be found */
1522 char filename[FILE_MAX];
1523 BLI_strncpy(filename, argv[1], sizeof(filename));
1524 BLI_path_cwd(filename, sizeof(filename));
1527 BPY_CTX_SETUP(ok = BPY_execute_filepath(C, filename, NULL));
1528 if (!ok && app_state.exit_code_on_error.python) {
1529 printf("\nError: script failed, file: '%s', exiting.\n", argv[1]);
1530 exit(app_state.exit_code_on_error.python);
1535 printf("\nError: you must specify a filepath after '%s'.\n", argv[0]);
1539 UNUSED_VARS(argc, argv, data);
1540 printf("This blender was built without python support\n");
1542 #endif /* WITH_PYTHON */
1545 static const char arg_handle_python_text_run_doc[] =
1547 "\tRun the given Python script text block"
1549 static int arg_handle_python_text_run(int argc, const char **argv, void *data)
1554 /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */
1556 /* Make the path absolute because its needed for relative linked blends to be found */
1557 struct Text *text = (struct Text *)BKE_libblock_find_name(ID_TXT, argv[1]);
1561 BPY_CTX_SETUP(ok = BPY_execute_text(C, text, NULL, false));
1564 printf("\nError: text block not found %s.\n", argv[1]);
1568 if (!ok && app_state.exit_code_on_error.python) {
1569 printf("\nError: script failed, text: '%s', exiting.\n", argv[1]);
1570 exit(app_state.exit_code_on_error.python);
1576 printf("\nError: you must specify a text block after '%s'.\n", argv[0]);
1580 UNUSED_VARS(argc, argv, data);
1581 printf("This blender was built without python support\n");
1583 #endif /* WITH_PYTHON */
1586 static const char arg_handle_python_expr_run_doc[] =
1588 "\tRun the given expression as a Python script"
1590 static int arg_handle_python_expr_run(int argc, const char **argv, void *data)
1595 /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */
1598 BPY_CTX_SETUP(ok = BPY_execute_string_ex(C, argv[1], false));
1599 if (!ok && app_state.exit_code_on_error.python) {
1600 printf("\nError: script failed, expr: '%s', exiting.\n", argv[1]);
1601 exit(app_state.exit_code_on_error.python);
1606 printf("\nError: you must specify a Python expression after '%s'.\n", argv[0]);
1610 UNUSED_VARS(argc, argv, data);
1611 printf("This blender was built without python support\n");
1613 #endif /* WITH_PYTHON */
1616 static const char arg_handle_python_console_run_doc[] =
1617 "\n\tRun blender with an interactive console"
1619 static int arg_handle_python_console_run(int UNUSED(argc), const char **argv, void *data)
1624 BPY_CTX_SETUP(BPY_execute_string(C, "__import__('code').interact()"));
1628 UNUSED_VARS(argv, data);
1629 printf("This blender was built without python support\n");
1631 #endif /* WITH_PYTHON */
1634 static const char arg_handle_python_exit_code_set_doc[] =
1636 "\tSet the exit-code in [0..255] to exit if a Python exception is raised\n"
1637 "\t(only for scripts executed from the command line), zero disables."
1639 static int arg_handle_python_exit_code_set(int argc, const char **argv, void *UNUSED(data))
1641 const char *arg_id = "--python-exit-code";
1643 const char *err_msg = NULL;
1644 const int min = 0, max = 255;
1646 if (!parse_int_strict_range(argv[1], NULL, min, max, &exit_code, &err_msg)) {
1647 printf("\nError: %s '%s %s', expected number in [%d..%d].\n", err_msg, arg_id, argv[1], min, max);
1651 app_state.exit_code_on_error.python = (unsigned char)exit_code;
1655 printf("\nError: you must specify an exit code number '%s'.\n", arg_id);
1660 static const char arg_handle_addons_set_doc[] =
1661 "\n\tComma separated list of add-ons (no spaces)"
1663 static int arg_handle_addons_set(int argc, const char **argv, void *data)
1665 /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */
1668 const char script_str[] =
1669 "from addon_utils import check, enable\n"
1670 "for m in '%s'.split(','):\n"
1671 " if check(m)[1] is False:\n"
1672 " enable(m, persistent=True)";
1673 const int slen = strlen(argv[1]) + (sizeof(script_str) - 2);
1674 char *str = malloc(slen);
1676 BLI_snprintf(str, slen, script_str, argv[1]);
1678 BLI_assert(strlen(str) + 1 == slen);
1679 BPY_CTX_SETUP(BPY_execute_string_ex(C, str, false));
1682 UNUSED_VARS(argv, data);
1683 #endif /* WITH_PYTHON */
1687 printf("\nError: you must specify a comma separated list after '--addons'.\n");
1692 static int arg_handle_load_file(int UNUSED(argc), const char **argv, void *data)
1698 /* Make the path absolute because its needed for relative linked blends to be found */
1699 char filename[FILE_MAX];
1701 /* note, we could skip these, but so far we always tried to load these files */
1702 if (argv[0][0] == '-') {
1703 fprintf(stderr, "unknown argument, loading as file: %s\n", argv[0]);
1706 BLI_strncpy(filename, argv[0], sizeof(filename));
1707 BLI_path_cwd(filename, sizeof(filename));
1710 BKE_reports_init(&reports, RPT_PRINT);
1711 WM_file_autoexec_init(filename);
1712 success = WM_file_read(C, filename, &reports);
1713 BKE_reports_clear(&reports);
1717 /* ensuer we use 'C->data.scene' for background render */
1718 CTX_wm_window_set(C, NULL);
1722 /* failed to load file, stop processing arguments if running in background mode */
1724 /* Set is_break if running in the background mode so
1725 * blender will return non-zero exit code which then
1726 * could be used in automated script to control how
1727 * good or bad things are.
1733 /* Just pretend a file was loaded, so the user can press Save and it'll save at the filename from the CLI. */
1734 BLI_strncpy(G.main->name, filename, FILE_MAX);
1735 G.relbase_valid = true;
1737 printf("... opened default scene instead; saving will write to %s\n", filename);
1746 void main_args_setup(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
1749 #define CB(a) a##_doc, a
1750 #define CB_EX(a, b) a##_doc_##b, a
1752 //BLI_argsAdd(ba, pass, short_arg, long_arg, doc, cb, C);
1754 /* end argument processing after -- */
1755 BLI_argsAdd(ba, -1, "--", NULL, CB(arg_handle_arguments_end), NULL);
1757 /* first pass: background mode, disable python and commands that exit after usage */
1758 BLI_argsAdd(ba, 1, "-h", "--help", CB(arg_handle_print_help), ba);
1760 BLI_argsAdd(ba, 1, "/?", NULL, CB_EX(arg_handle_print_help, win32), ba);
1762 BLI_argsAdd(ba, 1, "-v", "--version", CB(arg_handle_print_version), NULL);
1764 BLI_argsAdd(ba, 1, "-y", "--enable-autoexec", CB_EX(arg_handle_python_set, enable), (void *)true);
1765 BLI_argsAdd(ba, 1, "-Y", "--disable-autoexec", CB_EX(arg_handle_python_set, disable), (void *)false);
1767 BLI_argsAdd(ba, 1, NULL, "--disable-crash-handler", CB(arg_handle_crash_handler_disable), NULL);
1768 BLI_argsAdd(ba, 1, NULL, "--disable-abort-handler", CB(arg_handle_abort_handler_disable), NULL);
1770 BLI_argsAdd(ba, 1, "-b", "--background", CB(arg_handle_background_mode_set), NULL);
1772 BLI_argsAdd(ba, 1, "-a", NULL, CB(arg_handle_playback_mode), NULL);
1774 BLI_argsAdd(ba, 1, "-d", "--debug", CB(arg_handle_debug_mode_set), ba);
1777 BLI_argsAdd(ba, 1, NULL, "--debug-ffmpeg",
1778 CB_EX(arg_handle_debug_mode_generic_set, ffmpeg), (void *)G_DEBUG_FFMPEG);
1781 #ifdef WITH_FREESTYLE
1782 BLI_argsAdd(ba, 1, NULL, "--debug-freestyle",
1783 CB_EX(arg_handle_debug_mode_generic_set, freestyle), (void *)G_DEBUG_FREESTYLE);
1786 BLI_argsAdd(ba, 1, NULL, "--debug-python",
1787 CB_EX(arg_handle_debug_mode_generic_set, python), (void *)G_DEBUG_PYTHON);
1788 BLI_argsAdd(ba, 1, NULL, "--debug-events",
1789 CB_EX(arg_handle_debug_mode_generic_set, events), (void *)G_DEBUG_EVENTS);
1790 BLI_argsAdd(ba, 1, NULL, "--debug-handlers",
1791 CB_EX(arg_handle_debug_mode_generic_set, handlers), (void *)G_DEBUG_HANDLERS);
1792 BLI_argsAdd(ba, 1, NULL, "--debug-wm",
1793 CB_EX(arg_handle_debug_mode_generic_set, wm), (void *)G_DEBUG_WM);
1794 BLI_argsAdd(ba, 1, NULL, "--debug-all", CB(arg_handle_debug_mode_all), NULL);
1796 BLI_argsAdd(ba, 1, NULL, "--debug-io", CB(arg_handle_debug_mode_io), NULL);
1798 BLI_argsAdd(ba, 1, NULL, "--debug-fpe",
1799 CB(arg_handle_debug_fpe_set), NULL);
1802 BLI_argsAdd(ba, 1, NULL, "--debug-libmv", CB(arg_handle_debug_mode_libmv), NULL);
1804 #ifdef WITH_CYCLES_LOGGING
1805 BLI_argsAdd(ba, 1, NULL, "--debug-cycles", CB(arg_handle_debug_mode_cycles), NULL);
1807 BLI_argsAdd(ba, 1, NULL, "--debug-memory", CB(arg_handle_debug_mode_memory_set), NULL);
1809 BLI_argsAdd(ba, 1, NULL, "--debug-value",
1810 CB(arg_handle_debug_value_set), NULL);
1811 BLI_argsAdd(ba, 1, NULL, "--debug-jobs",
1812 CB_EX(arg_handle_debug_mode_generic_set, jobs), (void *)G_DEBUG_JOBS);
1813 BLI_argsAdd(ba, 1, NULL, "--debug-gpu",
1814 CB_EX(arg_handle_debug_mode_generic_set, gpu), (void *)G_DEBUG_GPU);
1815 BLI_argsAdd(ba, 1, NULL, "--debug-depsgraph",
1816 CB_EX(arg_handle_debug_mode_generic_set, depsgraph), (void *)G_DEBUG_DEPSGRAPH);
1817 BLI_argsAdd(ba, 1, NULL, "--debug-depsgraph-no-threads",
1818 CB_EX(arg_handle_debug_mode_generic_set, depsgraph_no_threads), (void *)G_DEBUG_DEPSGRAPH_NO_THREADS);
1819 BLI_argsAdd(ba, 1, NULL, "--debug-gpumem",
1820 CB_EX(arg_handle_debug_mode_generic_set, gpumem), (void *)G_DEBUG_GPU_MEM);
1822 BLI_argsAdd(ba, 1, NULL, "--verbose", CB(arg_handle_verbosity_set), NULL);
1824 BLI_argsAdd(ba, 1, NULL, "--factory-startup", CB(arg_handle_factory_startup_set), NULL);
1826 /* TODO, add user env vars? */
1827 BLI_argsAdd(ba, 1, NULL, "--env-system-datafiles", CB_EX(arg_handle_env_system_set, datafiles), NULL);
1828 BLI_argsAdd(ba, 1, NULL, "--env-system-scripts", CB_EX(arg_handle_env_system_set, scripts), NULL);
1829 BLI_argsAdd(ba, 1, NULL, "--env-system-python", CB_EX(arg_handle_env_system_set, python), NULL);
1831 /* second pass: custom window stuff */
1832 BLI_argsAdd(ba, 2, "-p", "--window-geometry", CB(arg_handle_window_geometry), NULL);
1833 BLI_argsAdd(ba, 2, "-w", "--window-border", CB(arg_handle_with_borders), NULL);
1834 BLI_argsAdd(ba, 2, "-W", "--window-borderless", CB(arg_handle_without_borders), NULL);
1835 BLI_argsAdd(ba, 2, "-con", "--start-console", CB(arg_handle_start_with_console), NULL);
1836 BLI_argsAdd(ba, 2, "-R", NULL, CB(arg_handle_register_extension), NULL);
1837 BLI_argsAdd(ba, 2, "-r", NULL, CB_EX(arg_handle_register_extension, silent), ba);
1838 BLI_argsAdd(ba, 2, NULL, "--no-native-pixels", CB(arg_handle_native_pixels_set), ba);
1840 /* third pass: disabling things and forcing settings */
1841 BLI_argsAddCase(ba, 3, "-nojoystick", 1, NULL, 0, CB(arg_handle_joystick_disable), syshandle);
1842 BLI_argsAddCase(ba, 3, "-noglsl", 1, NULL, 0, CB(arg_handle_glsl_disable), NULL);
1843 BLI_argsAddCase(ba, 3, "-noaudio", 1, NULL, 0, CB(arg_handle_audio_disable), NULL);
1844 BLI_argsAddCase(ba, 3, "-setaudio", 1, NULL, 0, CB(arg_handle_audio_set), NULL);
1846 /* fourth pass: processing arguments */
1847 BLI_argsAdd(ba, 4, "-g", NULL, CB(arg_handle_ge_parameters_set), syshandle);
1848 BLI_argsAdd(ba, 4, "-f", "--render-frame", CB(arg_handle_render_frame), C);
1849 BLI_argsAdd(ba, 4, "-a", "--render-anim", CB(arg_handle_render_animation), C);
1850 BLI_argsAdd(ba, 4, "-S", "--scene", CB(arg_handle_scene_set), C);
1851 BLI_argsAdd(ba, 4, "-s", "--frame-start", CB(arg_handle_frame_start_set), C);
1852 BLI_argsAdd(ba, 4, "-e", "--frame-end", CB(arg_handle_frame_end_set), C);
1853 BLI_argsAdd(ba, 4, "-j", "--frame-jump", CB(arg_handle_frame_skip_set), C);
1854 BLI_argsAdd(ba, 4, "-P", "--python", CB(arg_handle_python_file_run), C);
1855 BLI_argsAdd(ba, 4, NULL, "--python-text", CB(arg_handle_python_text_run), C);
1856 BLI_argsAdd(ba, 4, NULL, "--python-expr", CB(arg_handle_python_expr_run), C);
1857 BLI_argsAdd(ba, 4, NULL, "--python-console", CB(arg_handle_python_console_run), C);
1858 BLI_argsAdd(ba, 4, NULL, "--python-exit-code", CB(arg_handle_python_exit_code_set), NULL);
1859 BLI_argsAdd(ba, 4, NULL, "--addons", CB(arg_handle_addons_set), C);
1861 BLI_argsAdd(ba, 4, "-o", "--render-output", CB(arg_handle_output_set), C);
1862 BLI_argsAdd(ba, 4, "-E", "--engine", CB(arg_handle_engine_set), C);
1864 BLI_argsAdd(ba, 4, "-F", "--render-format", CB(arg_handle_image_type_set), C);
1865 BLI_argsAdd(ba, 1, "-t", "--threads", CB(arg_handle_threads_set), NULL);
1866 BLI_argsAdd(ba, 4, "-x", "--use-extension", CB(arg_handle_extension_set), C);
1874 * Needs to be added separately.
1876 void main_args_setup_post(bContext *C, bArgs *ba)
1878 BLI_argsParse(ba, 4, arg_handle_load_file, C);
1883 #endif /* WITH_PYTHON_MODULE */