PyObject *bpy_text_import_name(const char *name, int *found) { Text *text; char txtname[MAX_ID_NAME - 2]; int namelen = strlen(name); //XXX Main *maggie = bpy_import_main ? bpy_import_main:G.main; Main *maggie = bpy_import_main; *found = 0; if (!maggie) { printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n"); return NULL; } /* we know this cant be importable, the name is too long for blender! */ if (namelen >= (MAX_ID_NAME - 2) - 3) return NULL; memcpy(txtname, name, namelen); memcpy(&txtname[namelen], ".py", 4); text = BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2); if (!text) return NULL; else *found = 1; return bpy_text_import(text); }
void BPY_modules_load_user(bContext *C) { PyGILState_STATE gilstate; Main *bmain = CTX_data_main(C); Text *text; /* can happen on file load */ if (bmain == NULL) return; /* update pointers since this can run from a nested script * on file load */ if (py_call_level) { BPY_context_update(C); } bpy_context_set(C, &gilstate); for (text = bmain->text.first; text; text = text->id.next) { if (text->flags & TXT_ISSCRIPT && BLI_testextensie(text->id.name + 2, ".py")) { if (!(G.f & G_SCRIPT_AUTOEXEC)) { if (!(G.f & G_SCRIPT_AUTOEXEC_FAIL_QUIET)) { G.f |= G_SCRIPT_AUTOEXEC_FAIL; BLI_snprintf(G.autoexec_fail, sizeof(G.autoexec_fail), "Text '%s'", text->id.name + 2); printf("scripts disabled for \"%s\", skipping '%s'\n", bmain->name, text->id.name + 2); } } else { PyObject *module = bpy_text_import(text); if (module == NULL) { PyErr_Print(); PyErr_Clear(); } else { Py_DECREF(module); } /* check if the script loaded a new file */ if (bmain != CTX_data_main(C)) { break; } } } } bpy_context_clear(C, &gilstate); }