static void load_datablocks(Main *main_tmp, BlendHandle *bpy_openlib, const char *path, int idcode) { LinkNode *names = NULL; int totnames_dummy; names = BLO_blendhandle_get_datablock_names(bpy_openlib, idcode, &totnames_dummy); int i = 0; LinkNode *n = names; while (n) { BLO_library_link_named_part(main_tmp, &bpy_openlib, idcode, (char *)n->link); n = (LinkNode *)n->next; i++; } BLI_linklist_free(names, free); /* free linklist *and* each node's data */ }
static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) { Main *bmain = CTX_data_main(BPy_GetContext()); Main *mainl = NULL; int err = 0; BKE_main_id_flag_all(bmain, LIB_TAG_PRE_EXISTING, true); /* here appending/linking starts */ mainl = BLO_library_link_begin(bmain, &(self->blo_handle), self->relpath); { int idcode_step = 0, idcode; while ((idcode = BKE_idcode_iter_step(&idcode_step))) { if (BKE_idcode_is_linkable(idcode)) { const char *name_plural = BKE_idcode_to_name_plural(idcode); PyObject *ls = PyDict_GetItemString(self->dict, name_plural); // printf("lib: %s\n", name_plural); if (ls && PyList_Check(ls)) { /* loop */ Py_ssize_t size = PyList_GET_SIZE(ls); Py_ssize_t i; PyObject *item; const char *item_str; for (i = 0; i < size; i++) { item = PyList_GET_ITEM(ls, i); item_str = _PyUnicode_AsString(item); // printf(" %s\n", item_str); if (item_str) { ID *id = BLO_library_link_named_part(mainl, &(self->blo_handle), idcode, item_str); if (id) { #ifdef USE_RNA_DATABLOCKS /* swap name for pointer to the id */ Py_DECREF(item); item = PyCapsule_New((void *)id, NULL, NULL); #endif } else { bpy_lib_exit_warn_idname(self, name_plural, item_str); /* just warn for now */ /* err = -1; */ #ifdef USE_RNA_DATABLOCKS item = Py_INCREF_RET(Py_None); #endif } /* ID or None */ } else { /* XXX, could complain about this */ bpy_lib_exit_warn_type(self, item); PyErr_Clear(); #ifdef USE_RNA_DATABLOCKS item = Py_INCREF_RET(Py_None); #endif } #ifdef USE_RNA_DATABLOCKS PyList_SET_ITEM(ls, i, item); #endif } } } } } if (err == -1) { /* exception raised above, XXX, this leaks some memory */ BLO_blendhandle_close(self->blo_handle); self->blo_handle = NULL; BKE_main_id_flag_all(bmain, LIB_TAG_PRE_EXISTING, false); return NULL; } else { Library *lib = mainl->curlib; /* newly added lib, assign before append end */ BLO_library_link_end(mainl, &(self->blo_handle), self->flag, NULL, NULL); BLO_blendhandle_close(self->blo_handle); self->blo_handle = NULL; /* copied from wm_operator.c */ { /* mark all library linked objects to be updated */ BKE_main_lib_objects_recalc_all(G.main); /* append, rather than linking */ if ((self->flag & FILE_LINK) == 0) { BKE_library_make_local(bmain, lib, true); } } BKE_main_id_flag_all(bmain, LIB_TAG_PRE_EXISTING, false); /* finally swap the capsules for real bpy objects * important since BLO_library_append_end initializes NodeTree types used by srna->refine */ { int idcode_step = 0, idcode; while ((idcode = BKE_idcode_iter_step(&idcode_step))) { if (BKE_idcode_is_linkable(idcode)) { const char *name_plural = BKE_idcode_to_name_plural(idcode); PyObject *ls = PyDict_GetItemString(self->dict, name_plural); if (ls && PyList_Check(ls)) { Py_ssize_t size = PyList_GET_SIZE(ls); Py_ssize_t i; PyObject *item; for (i = 0; i < size; i++) { item = PyList_GET_ITEM(ls, i); if (PyCapsule_CheckExact(item)) { PointerRNA id_ptr; ID *id; id = PyCapsule_GetPointer(item, NULL); Py_DECREF(item); RNA_id_pointer_create(id, &id_ptr); item = pyrna_struct_CreatePyObject(&id_ptr); PyList_SET_ITEM(ls, i, item); } } } } } } Py_RETURN_NONE; } }