Changeset View
Changeset View
Standalone View
Standalone View
source/creator/creator_args.c
| Show All 38 Lines | |||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_string_utf8.h" | #include "BLI_string_utf8.h" | ||||
| #include "BLI_path_util.h" | #include "BLI_path_util.h" | ||||
| #include "BLI_fileops.h" | #include "BLI_fileops.h" | ||||
| #include "BLI_mempool.h" | #include "BLI_mempool.h" | ||||
| #include "BKE_blender_undo.h" | |||||
| #include "BKE_blender_version.h" | #include "BKE_blender_version.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| ▲ Show 20 Lines • Show All 1,486 Lines • ▼ Show 20 Lines | #ifdef WITH_PYTHON | ||||
| if (argc > 1) { | if (argc > 1) { | ||||
| /* Make the path absolute because its needed for relative linked blends to be found */ | /* Make the path absolute because its needed for relative linked blends to be found */ | ||||
| char filename[FILE_MAX]; | char filename[FILE_MAX]; | ||||
| BLI_strncpy(filename, argv[1], sizeof(filename)); | BLI_strncpy(filename, argv[1], sizeof(filename)); | ||||
| BLI_path_cwd(filename, sizeof(filename)); | BLI_path_cwd(filename, sizeof(filename)); | ||||
| bool ok; | bool ok; | ||||
| BPY_CTX_SETUP(ok = BPY_execute_filepath(C, filename, NULL)); | BPY_CTX_SETUP(ok = BPY_execute_filepath(C, filename, NULL)); | ||||
| if (!ok && app_state.exit_code_on_error.python) { | |||||
| if (ok) { | |||||
| BKE_undo_write(C, "--python"); /* save current state */ | |||||
| } | |||||
| else if (app_state.exit_code_on_error.python) { | |||||
| printf("\nError: script failed, file: '%s', exiting.\n", argv[1]); | printf("\nError: script failed, file: '%s', exiting.\n", argv[1]); | ||||
| exit(app_state.exit_code_on_error.python); | exit(app_state.exit_code_on_error.python); | ||||
| } | } | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else { | else { | ||||
| printf("\nError: you must specify a filepath after '%s'.\n", argv[0]); | printf("\nError: you must specify a filepath after '%s'.\n", argv[0]); | ||||
| return 0; | return 0; | ||||
| Show All 23 Lines | if (argc > 1) { | ||||
| if (text) { | if (text) { | ||||
| BPY_CTX_SETUP(ok = BPY_execute_text(C, text, NULL, false)); | BPY_CTX_SETUP(ok = BPY_execute_text(C, text, NULL, false)); | ||||
| } | } | ||||
| else { | else { | ||||
| printf("\nError: text block not found %s.\n", argv[1]); | printf("\nError: text block not found %s.\n", argv[1]); | ||||
| ok = false; | ok = false; | ||||
| } | } | ||||
| if (!ok && app_state.exit_code_on_error.python) { | if (ok) { | ||||
| BKE_undo_write(C, "--python-text"); /* save current state */ | |||||
| } | |||||
| else if (app_state.exit_code_on_error.python) { | |||||
| printf("\nError: script failed, text: '%s', exiting.\n", argv[1]); | printf("\nError: script failed, text: '%s', exiting.\n", argv[1]); | ||||
| exit(app_state.exit_code_on_error.python); | exit(app_state.exit_code_on_error.python); | ||||
| } | } | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else { | else { | ||||
| printf("\nError: you must specify a text block after '%s'.\n", argv[0]); | printf("\nError: you must specify a text block after '%s'.\n", argv[0]); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| #else | #else | ||||
| UNUSED_VARS(argc, argv, data); | UNUSED_VARS(argc, argv, data); | ||||
| Show All 10 Lines | |||||
| { | { | ||||
| #ifdef WITH_PYTHON | #ifdef WITH_PYTHON | ||||
| bContext *C = data; | bContext *C = data; | ||||
| /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */ | /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */ | ||||
| if (argc > 1) { | if (argc > 1) { | ||||
| bool ok; | bool ok; | ||||
| BPY_CTX_SETUP(ok = BPY_execute_string_ex(C, argv[1], false)); | BPY_CTX_SETUP(ok = BPY_execute_string_ex(C, argv[1], false)); | ||||
| if (!ok && app_state.exit_code_on_error.python) { | |||||
| if (ok) { | |||||
| BKE_undo_write(C, "--python-expr"); /* save current state */ | |||||
| } | |||||
| else if (app_state.exit_code_on_error.python) { | |||||
| printf("\nError: script failed, expr: '%s', exiting.\n", argv[1]); | printf("\nError: script failed, expr: '%s', exiting.\n", argv[1]); | ||||
| exit(app_state.exit_code_on_error.python); | exit(app_state.exit_code_on_error.python); | ||||
| } | } | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else { | else { | ||||
| printf("\nError: you must specify a Python expression after '%s'.\n", argv[0]); | printf("\nError: you must specify a Python expression after '%s'.\n", argv[0]); | ||||
| return 0; | return 0; | ||||
| ▲ Show 20 Lines • Show All 279 Lines • Show Last 20 Lines | |||||