diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-06-14 15:17:38 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-06-14 15:18:44 +0300 |
commit | 18629918622c1acfb4cc69176c98df2e13589c00 (patch) | |
tree | f68f6b9f86e396e26629669df0ec6f7cfafad7fc /source | |
parent | b9fe261255cba067c055caac603e9abe4d089e84 (diff) |
Fix '--addons' argument
- only enable addons which aren't already enabled
- use 'persistent' load option (new file wont reset)
Diffstat (limited to 'source')
-rw-r--r-- | source/creator/creator.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/source/creator/creator.c b/source/creator/creator.c index 237dcec4b26..8c1ae3d8c87 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -1325,11 +1325,18 @@ static int set_addons(int argc, const char **argv, void *data) /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */ if (argc > 1) { #ifdef WITH_PYTHON - const int slen = strlen(argv[1]) + 128; + const char script_str[] = + "from addon_utils import check, enable\n" + "for m in '%s'.split(','):\n" + " if check(m)[1] is False:\n" + " enable(m, persistent=True)"; + const int slen = strlen(argv[1]) + (sizeof(script_str) - 2); char *str = malloc(slen); bContext *C = data; - BLI_snprintf(str, slen, "[__import__('addon_utils').enable(i, default_set=False) for i in '%s'.split(',')]", argv[1]); - BPY_CTX_SETUP(BPY_string_exec(C, str)); + BLI_snprintf(str, slen, script_str, argv[1]); + + BLI_assert(strlen(str) + 1 == slen); + BPY_CTX_SETUP(BPY_string_exec_ex(C, str, false)); free(str); #else UNUSED_VARS(argv, data); |