Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-06-11 09:57:31 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-06-11 14:54:06 +0300
commit958c20872a662808be8353b33904f1e30c2d0fcf (patch)
tree0ce531a5c217218f4efdee0811bb3153ff8a17ff /source/creator
parent087c82e392bc4cd175421fc5bc5faa88d218c224 (diff)
Add argument --python-expr to pass Python directly
This works like Python's -c argument, handy to be able to avoid writing small scripts to disk.
Diffstat (limited to 'source/creator')
-rw-r--r--source/creator/creator.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/source/creator/creator.c b/source/creator/creator.c
index 2a96988a0bd..237dcec4b26 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -297,6 +297,7 @@ static int print_help(int UNUSED(argc), const char **UNUSED(argv), void *data)
BLI_argsPrintArgDoc(ba, "--python");
BLI_argsPrintArgDoc(ba, "--python-text");
+ BLI_argsPrintArgDoc(ba, "--python-expr");
BLI_argsPrintArgDoc(ba, "--python-console");
BLI_argsPrintArgDoc(ba, "--addons");
@@ -1283,6 +1284,27 @@ static int run_python_text(int argc, const char **argv, void *data)
#endif /* WITH_PYTHON */
}
+static int run_python_expr(int argc, const char **argv, void *data)
+{
+#ifdef WITH_PYTHON
+ bContext *C = data;
+
+ /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */
+ if (argc > 1) {
+ BPY_CTX_SETUP(BPY_string_exec_ex(C, argv[1], false));
+ return 1;
+ }
+ else {
+ printf("\nError: you must specify a Python expression after '%s'.\n", argv[0]);
+ return 0;
+ }
+#else
+ UNUSED_VARS(argc, argv, data);
+ printf("This blender was built without python support\n");
+ return 0;
+#endif /* WITH_PYTHON */
+}
+
static int run_python_console(int UNUSED(argc), const char **argv, void *data)
{
#ifdef WITH_PYTHON
@@ -1549,6 +1571,7 @@ static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
BLI_argsAdd(ba, 4, "-j", "--frame-jump", "<frames>\n\tSet number of frames to step forward after each rendered frame", set_skip_frame, C);
BLI_argsAdd(ba, 4, "-P", "--python", "<filename>\n\tRun the given Python script file", run_python_file, C);
BLI_argsAdd(ba, 4, NULL, "--python-text", "<name>\n\tRun the given Python script text block", run_python_text, C);
+ BLI_argsAdd(ba, 4, NULL, "--python-expr", "<expression>\n\tRun the given expression as a Python script", run_python_expr, C);
BLI_argsAdd(ba, 4, NULL, "--python-console", "\n\tRun blender with an interactive console", run_python_console, C);
BLI_argsAdd(ba, 4, NULL, "--addons", "\n\tComma separated list of addons (no spaces)", set_addons, C);