Blender V4.5
bpy_library_load.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
15
16#include <Python.h>
17#include <cstddef>
18
19#include "BLI_linklist.h"
20#include "BLI_path_utils.hh"
21#include "BLI_string.h"
22#include "BLI_utildefines.h"
23
25#include "BKE_context.hh"
26#include "BKE_idtype.hh"
27#include "BKE_lib_id.hh"
28#include "BKE_main.hh"
29#include "BKE_report.hh"
30
31#include "DNA_space_types.h" /* FILE_LINK, FILE_RELPATH */
32
33#include "BLO_readfile.hh"
34
35#include "bpy_capi_utils.hh"
36#include "bpy_library.hh"
37
39#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
41
42/* nifty feature. swap out strings for RNA data */
43#define USE_RNA_DATABLOCKS
44
45#ifdef USE_RNA_DATABLOCKS
46# include "RNA_access.hh"
47# include "bpy_rna.hh"
48#endif
49
51 PyObject_HEAD /* Required Python macro. */
52 /* Collection iterator specific parts. */
54 char abspath[FILE_MAX]; /* absolute path */
55 BlendHandle *blo_handle;
56 /* Referenced by `blo_handle`, so stored here to keep alive for long enough. */
59
60 int flag;
61
64
65 PyObject *dict;
66 /* Borrowed reference to the `bmain`, taken from the RNA instance of #RNA_BlendDataLibraries.
67 * Defaults to #G.main, Otherwise use a temporary #Main when `bmain_is_temp` is true. */
70};
71
72static PyObject *bpy_lib_load(BPy_PropertyRNA *self, PyObject *args, PyObject *kw);
73static PyObject *bpy_lib_enter(BPy_Library *self);
74static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *args);
75static PyObject *bpy_lib_dir(BPy_Library *self);
76
77#ifdef __GNUC__
78# ifdef __clang__
79# pragma clang diagnostic push
80# pragma clang diagnostic ignored "-Wcast-function-type"
81# else
82# pragma GCC diagnostic push
83# pragma GCC diagnostic ignored "-Wcast-function-type"
84# endif
85#endif
86
87static PyMethodDef bpy_lib_methods[] = {
88 {"__enter__", (PyCFunction)bpy_lib_enter, METH_NOARGS},
89 {"__exit__", (PyCFunction)bpy_lib_exit, METH_VARARGS},
90 {"__dir__", (PyCFunction)bpy_lib_dir, METH_NOARGS},
91 {nullptr} /* sentinel */
92};
93
94#ifdef __GNUC__
95# ifdef __clang__
96# pragma clang diagnostic pop
97# else
98# pragma GCC diagnostic pop
99# endif
100#endif
101
103{
104 Py_XDECREF(self->dict);
105 Py_TYPE(self)->tp_free(self);
106}
107
108static PyTypeObject bpy_lib_Type = {
109 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
110 /*tp_name*/ "bpy_lib",
111 /*tp_basicsize*/ sizeof(BPy_Library),
112 /*tp_itemsize*/ 0,
113 /*tp_dealloc*/ (destructor)bpy_lib_dealloc,
114 /*tp_vectorcall_offset*/ 0,
115 /*tp_getattr*/ nullptr,
116 /*tp_setattr*/ nullptr,
117 /*tp_as_async*/ nullptr,
118 /*tp_repr*/ nullptr,
119 /*tp_as_number*/ nullptr,
120 /*tp_as_sequence*/ nullptr,
121 /*tp_as_mapping*/ nullptr,
122 /*tp_hash*/ nullptr,
123 /*tp_call*/ nullptr,
124 /*tp_str*/ nullptr,
125 /*tp_getattro*/ PyObject_GenericGetAttr,
126 /*tp_setattro*/ nullptr,
127 /*tp_as_buffer*/ nullptr,
128 /*tp_flags*/ Py_TPFLAGS_DEFAULT,
129 /*tp_doc*/ nullptr,
130 /*tp_traverse*/ nullptr,
131 /*tp_clear*/ nullptr,
132 /*tp_richcompare*/ nullptr,
133 /*tp_weaklistoffset*/ 0,
134 /*tp_iter*/ nullptr,
135 /*tp_iternext*/ nullptr,
136 /*tp_methods*/ bpy_lib_methods,
137 /*tp_members*/ nullptr,
138 /*tp_getset*/ nullptr,
139 /*tp_base*/ nullptr,
140 /*tp_dict*/ nullptr,
141 /*tp_descr_get*/ nullptr,
142 /*tp_descr_set*/ nullptr,
143 /*tp_dictoffset*/ offsetof(BPy_Library, dict),
144 /*tp_init*/ nullptr,
145 /*tp_alloc*/ nullptr,
146 /*tp_new*/ nullptr,
147 /*tp_free*/ nullptr,
148 /*tp_is_gc*/ nullptr,
149 /*tp_bases*/ nullptr,
150 /*tp_mro*/ nullptr,
151 /*tp_cache*/ nullptr,
152 /*tp_subclasses*/ nullptr,
153 /*tp_weaklist*/ nullptr,
154 /*tp_del*/ nullptr,
155 /*tp_version_tag*/ 0,
156 /*tp_finalize*/ nullptr,
157 /*tp_vectorcall*/ nullptr,
158};
159
161 /* Wrap. */
162 bpy_lib_load_doc,
163 ".. method:: load("
164 "filepath, "
165 "link=False, "
166 "relative=False, "
167 "assets_only=False, "
168 "create_liboverrides=False, "
169 "reuse_liboverrides=False, "
170 "create_liboverrides_runtime=False)\n"
171 "\n"
172 " Returns a context manager which exposes 2 library objects on entering.\n"
173 " Each object has attributes matching bpy.data which are lists of strings to be linked.\n"
174 "\n"
175 " :arg filepath: The path to a blend file.\n"
176 " :type filepath: str | bytes\n"
177 " :arg link: When False reference to the original file is lost.\n"
178 " :type link: bool\n"
179 " :arg relative: When True the path is stored relative to the open blend file.\n"
180 " :type relative: bool\n"
181 " :arg assets_only: If True, only list data-blocks marked as assets.\n"
182 " :type assets_only: bool\n"
183 " :arg create_liboverrides: If True and ``link`` is True, liboverrides will\n"
184 " be created for linked data.\n"
185 " :type create_liboverrides: bool\n"
186 " :arg reuse_liboverrides: If True and ``create_liboverride`` is True,\n"
187 " search for existing liboverride first.\n"
188 " :type reuse_liboverrides: bool\n"
189 " :arg create_liboverrides_runtime: If True and ``create_liboverride`` is True,\n"
190 " create (or search for existing) runtime liboverride.\n"
191 " :type create_liboverrides_runtime: bool\n");
192static PyObject *bpy_lib_load(BPy_PropertyRNA *self, PyObject *args, PyObject *kw)
193{
194 Main *bmain_base = CTX_data_main(BPY_context_get());
195 Main *bmain = static_cast<Main *>(self->ptr->data); /* Typically #G_MAIN */
197 PyC_UnicodeAsBytesAndSize_Data filepath_data = {nullptr};
198 bool is_rel = false, is_link = false, use_assets_only = false;
199 bool create_liboverrides = false, reuse_liboverrides = false,
200 create_liboverrides_runtime = false;
201
202 static const char *_keywords[] = {
203 "filepath",
204 "link",
205 "relative",
206 "assets_only",
207 "create_liboverrides",
208 "reuse_liboverrides",
209 "create_liboverrides_runtime",
210 nullptr,
211 };
212 static _PyArg_Parser _parser = {
214 "O&" /* `filepath` */
215 /* Optional keyword only arguments. */
216 "|$"
217 "O&" /* `link` */
218 "O&" /* `relative` */
219 "O&" /* `assets_only` */
220 "O&" /* `create_liboverrides` */
221 "O&" /* `reuse_liboverrides` */
222 "O&" /* `create_liboverrides_runtime` */
223 ":load",
224 _keywords,
225 nullptr,
226 };
227 if (!_PyArg_ParseTupleAndKeywordsFast(args,
228 kw,
229 &_parser,
231 &filepath_data,
233 &is_link,
235 &is_rel,
237 &use_assets_only,
239 &create_liboverrides,
241 &reuse_liboverrides,
243 &create_liboverrides_runtime))
244 {
245 return nullptr;
246 }
247
248 const char *blendfile_path = BKE_main_blendfile_path(bmain);
249 char filepath_rel[FILE_MAX];
250 char filepath_abs[FILE_MAX];
251
252 STRNCPY(filepath_rel, filepath_data.value);
253 STRNCPY(filepath_abs, filepath_rel);
254 BLI_path_abs(filepath_abs, blendfile_path);
255 Py_XDECREF(filepath_data.value_coerce);
256
257 if (blendfile_path[0]) {
258 /* NOTE: intentionally leave `filepath_abs` and only use normalizing for comparison.
259 * It's important that this comparison matches read-files logic for matching paths.
260 * See the logic inside #BKE_blendfile_link.
261 *
262 * This means it's not necessary to check if the paths are *actually* the same.
263 * It's possible to load from this file if a user makes a symbolic-link - for example.
264 * See #140929. */
265 char filepath_abs_normalized[FILE_MAX];
266 STRNCPY(filepath_abs_normalized, filepath_abs);
267 BLI_path_normalize(filepath_abs_normalized);
268 if (BLI_path_cmp(filepath_abs_normalized, blendfile_path) == 0) {
269 PyErr_SetString(PyExc_ValueError, "Cannot load from the current blend file.");
270 return nullptr;
271 }
272 }
273
274 if (!is_link && create_liboverrides) {
275 PyErr_SetString(PyExc_ValueError, "`link` is False but `create_liboverrides` is True");
276 return nullptr;
277 }
278 if (!create_liboverrides && reuse_liboverrides) {
279 PyErr_SetString(PyExc_ValueError,
280 "`create_liboverrides` is False but `reuse_liboverrides` is True");
281 return nullptr;
282 }
283 if (!create_liboverrides && create_liboverrides_runtime) {
284 PyErr_SetString(PyExc_ValueError,
285 "`create_liboverrides` is False but `create_liboverrides_runtime` is True");
286 return nullptr;
287 }
288
289 ret = PyObject_New(BPy_Library, &bpy_lib_Type);
290
291 STRNCPY(ret->relpath, filepath_rel);
292 STRNCPY(ret->abspath, filepath_abs);
293
294 ret->bmain = bmain;
295 ret->bmain_is_temp = (bmain != bmain_base);
296
297 ret->blo_handle = nullptr;
298 ret->flag = ((is_link ? FILE_LINK : 0) | (is_rel ? FILE_RELPATH : 0) |
299 (use_assets_only ? FILE_ASSETS_ONLY : 0));
300 ret->create_liboverrides = create_liboverrides;
301 ret->liboverride_flags = eBKELibLinkOverride(
302 create_liboverrides ?
303 ((reuse_liboverrides ? BKE_LIBLINK_OVERRIDE_USE_EXISTING_LIBOVERRIDES : 0) |
304 (create_liboverrides_runtime ? BKE_LIBLINK_OVERRIDE_CREATE_RUNTIME : 0)) :
305 0);
306
307 ret->dict = _PyDict_NewPresized(INDEX_ID_MAX);
308
309 return (PyObject *)ret;
310}
311
312static PyObject *_bpy_names(BPy_Library *self, int blocktype)
313{
314 PyObject *list;
315 LinkNode *l, *names;
316 int totnames;
317
319 self->blo_handle, blocktype, (self->flag & FILE_ASSETS_ONLY) != 0, &totnames);
320 list = PyList_New(totnames);
321
322 if (names) {
323 int counter = 0;
324 for (l = names; l; l = l->next) {
325 PyList_SET_ITEM(list, counter, PyUnicode_FromString((char *)l->link));
326 counter++;
327 }
328 BLI_linklist_freeN(names); /* free linklist *and* each node's data */
329 }
330
331 return list;
332}
333
335{
336 PyObject *ret;
337 BPy_Library *self_from;
338 ReportList *reports = &self->reports;
339 BlendFileReadReport *bf_reports = &self->bf_reports;
340
342 memset(bf_reports, 0, sizeof(*bf_reports));
343 bf_reports->reports = reports;
344
345 self->blo_handle = BLO_blendhandle_from_file(self->abspath, bf_reports);
346
347 if (self->blo_handle == nullptr) {
348 if (BPy_reports_to_error(reports, PyExc_IOError, true) != -1) {
349 PyErr_Format(PyExc_IOError, "load: %s failed to open blend file", self->abspath);
350 }
351 return nullptr;
352 }
353
354 PyObject *from_dict = _PyDict_NewPresized(INDEX_ID_MAX);
355
356 int i = 0, code;
357 while ((code = BKE_idtype_idcode_iter_step(&i))) {
359 const char *name_plural = BKE_idtype_idcode_to_name_plural(code);
360 PyObject *str = PyUnicode_FromString(name_plural);
361 PyObject *item;
362
363 PyDict_SetItem(self->dict, str, item = PyList_New(0));
364 Py_DECREF(item);
365 PyDict_SetItem(from_dict, str, item = _bpy_names(self, code));
366 Py_DECREF(item);
367
368 Py_DECREF(str);
369 }
370 }
371
372 /* create a dummy */
373 self_from = PyObject_New(BPy_Library, &bpy_lib_Type);
374 STRNCPY(self_from->relpath, self->relpath);
375 STRNCPY(self_from->abspath, self->abspath);
376
377 self_from->blo_handle = nullptr;
378 self_from->flag = 0;
379 self_from->create_liboverrides = false;
381 self_from->dict = from_dict; /* owns the dict */
382
383 /* return pair */
384 ret = PyTuple_New(2);
385 PyTuple_SET_ITEMS(ret, (PyObject *)self_from, (PyObject *)self);
386 Py_INCREF(self);
387
389
390 return ret;
391}
392
394 const char *name_plural,
395 const char *idname)
396{
397 PyObject *exc, *val, *tb;
398 PyErr_Fetch(&exc, &val, &tb);
399 if (PyErr_WarnFormat(PyExc_UserWarning,
400 1,
401 "load: '%s' does not contain %s[\"%s\"]",
402 self->abspath,
403 name_plural,
404 idname))
405 {
406 /* Spurious errors can appear at shutdown */
407 if (PyErr_ExceptionMatches(PyExc_Warning)) {
408 PyErr_WriteUnraisable((PyObject *)self);
409 }
410 }
411 PyErr_Restore(exc, val, tb);
412}
413
414static void bpy_lib_exit_warn_type(BPy_Library *self, PyObject *item)
415{
416 PyObject *exc, *val, *tb;
417 PyErr_Fetch(&exc, &val, &tb);
418 if (PyErr_WarnFormat(PyExc_UserWarning,
419 1,
420 "load: '%s' expected a string type, not a %.200s",
421 self->abspath,
422 Py_TYPE(item)->tp_name))
423 {
424 /* Spurious errors can appear at shutdown */
425 if (PyErr_ExceptionMatches(PyExc_Warning)) {
426 PyErr_WriteUnraisable((PyObject *)self);
427 }
428 }
429 PyErr_Restore(exc, val, tb);
430}
431
438
442{
443 /* Since `bpy_lib_exit` loops over all ID types, all items in `lapp_context` end up being looped
444 * over for each ID type, so when it does not match the item can simply be skipped: it either has
445 * already been processed, or will be processed in a later loop. */
446 if (BKE_blendfile_link_append_context_item_idcode_get(lapp_context, item) != data.idcode) {
447 return true;
448 }
449
450 const int py_list_index = POINTER_AS_INT(
452 ID *new_id = BKE_blendfile_link_append_context_item_newid_get(lapp_context, item);
453 ID *liboverride_id = data.py_library->create_liboverrides ?
455 item) :
456 nullptr;
457
458 BLI_assert(py_list_index < data.py_list_size);
459
460 /* Fully invalid items (which got set to `Py_None` already in first loop of `bpy_lib_exit`)
461 * should never be accessed here, since their index should never be set to any item in
462 * `lapp_context`. */
463 PyObject *item_src = PyList_GET_ITEM(data.py_list, py_list_index);
464 BLI_assert(item_src != Py_None);
465
466 PyObject *py_item;
467 if (liboverride_id != nullptr) {
468 PointerRNA newid_ptr = RNA_id_pointer_create(liboverride_id);
469 py_item = pyrna_struct_CreatePyObject(&newid_ptr);
470 }
471 else if (new_id != nullptr) {
472 PointerRNA newid_ptr = RNA_id_pointer_create(new_id);
473 py_item = pyrna_struct_CreatePyObject(&newid_ptr);
474 }
475 else {
476 const char *item_idname = PyUnicode_AsUTF8(item_src);
477 const char *idcode_name_plural = BKE_idtype_idcode_to_name_plural(data.idcode);
478
479 bpy_lib_exit_warn_idname(data.py_library, idcode_name_plural, item_idname);
480
481 py_item = Py_NewRef(Py_None);
482 }
483
484 PyList_SET_ITEM(data.py_list, py_list_index, py_item);
485
486 Py_DECREF(item_src);
487
488 return true;
489}
490
491static PyObject *bpy_lib_exit(BPy_Library *self, PyObject * /*args*/)
492{
493 Main *bmain = self->bmain;
494 const bool do_append = ((self->flag & FILE_LINK) == 0);
495 const bool create_liboverrides = self->create_liboverrides;
496 /* Code in #bpy_lib_load should have raised exception in case of incompatible parameter values.
497 */
498 BLI_assert(!do_append || !create_liboverrides);
499
501
502 /* here appending/linking starts */
503 const int id_tag_extra = self->bmain_is_temp ? int(ID_TAG_TEMP_MAIN) : 0;
504 LibraryLink_Params liblink_params;
505 BLO_library_link_params_init(&liblink_params, bmain, self->flag, id_tag_extra);
506
508 &liblink_params);
509 /* NOTE: Transfers the ownership of the `blo_handle` to the `lapp_context`. */
510 BKE_blendfile_link_append_context_library_add(lapp_context, self->abspath, self->blo_handle);
511 self->blo_handle = nullptr;
512
513 int idcode_step = 0;
514 short idcode;
515 while ((idcode = BKE_idtype_idcode_iter_step(&idcode_step))) {
516 if (!BKE_idtype_idcode_is_linkable(idcode) || (idcode == ID_WS && !do_append)) {
517 continue;
518 }
519
520 const char *name_plural = BKE_idtype_idcode_to_name_plural(idcode);
521 PyObject *ls = PyDict_GetItemString(self->dict, name_plural);
522 // printf("lib: %s\n", name_plural);
523 if (ls == nullptr || !PyList_Check(ls)) {
524 continue;
525 }
526
527 const Py_ssize_t size = PyList_GET_SIZE(ls);
528 if (size == 0) {
529 continue;
530 }
531
532 /* loop */
533 for (Py_ssize_t i = 0; i < size; i++) {
534 PyObject *item_src = PyList_GET_ITEM(ls, i);
535 const char *item_idname = PyUnicode_AsUTF8(item_src);
536
537 // printf(" %s\n", item_idname);
538
539 /* NOTE: index of item in py list is stored in userdata pointer, so that it can be found
540 * later on to replace the ID name by the actual ID pointer. */
541 if (item_idname != nullptr) {
543 lapp_context, item_idname, idcode, POINTER_FROM_INT(i));
545 }
546 else {
547 /* XXX, could complain about this */
548 bpy_lib_exit_warn_type(self, item_src);
549 PyErr_Clear();
550
551#ifdef USE_RNA_DATABLOCKS
552 /* We can replace the item immediately with `None`. */
553 PyObject *py_item = Py_NewRef(Py_None);
554 PyList_SET_ITEM(ls, i, py_item);
555 Py_DECREF(item_src);
556#endif
557 }
558 }
559 }
560
562
563 BKE_blendfile_link(lapp_context, nullptr);
564 if (do_append) {
565 BKE_blendfile_append(lapp_context, nullptr);
566 }
567 else if (create_liboverrides) {
568 BKE_blendfile_override(lapp_context, self->liboverride_flags, nullptr);
569 }
570
572
573/* If enabled, replace named items in given lists by the final matching new ID pointer. */
574#ifdef USE_RNA_DATABLOCKS
575 idcode_step = 0;
576 while ((idcode = BKE_idtype_idcode_iter_step(&idcode_step))) {
577 if (!BKE_idtype_idcode_is_linkable(idcode) || (idcode == ID_WS && !do_append)) {
578 continue;
579 }
580 const char *name_plural = BKE_idtype_idcode_to_name_plural(idcode);
581 PyObject *ls = PyDict_GetItemString(self->dict, name_plural);
582 // printf("lib: %s\n", name_plural);
583 if (ls == nullptr || !PyList_Check(ls)) {
584 continue;
585 }
586
587 const Py_ssize_t size = PyList_GET_SIZE(ls);
588 if (size == 0) {
589 continue;
590 }
591
592 /* Loop over linked items in `lapp_context` to find matching python one in the list, and
593 * replace them with proper ID pointer. */
595 iter_data.idcode = idcode;
596 iter_data.py_library = self;
597 iter_data.py_list = ls;
598 iter_data.py_list_size = size;
600 lapp_context,
601 [&iter_data](BlendfileLinkAppendContext *lapp_context,
602 BlendfileLinkAppendContextItem *item) -> bool {
603 return bpy_lib_exit_lapp_context_items_cb(lapp_context, item, iter_data);
604 },
606 }
607#endif // USE_RNA_DATABLOCKS
608
611
612 BKE_reports_free(&self->reports);
613
614 Py_RETURN_NONE;
615}
616
617static PyObject *bpy_lib_dir(BPy_Library *self)
618{
619 return PyDict_Keys(self->dict);
620}
621
622#ifdef __GNUC__
623# ifdef __clang__
624# pragma clang diagnostic push
625# pragma clang diagnostic ignored "-Wcast-function-type"
626# else
627# pragma GCC diagnostic push
628# pragma GCC diagnostic ignored "-Wcast-function-type"
629# endif
630#endif
631
633 "load",
634 (PyCFunction)bpy_lib_load,
635 METH_VARARGS | METH_KEYWORDS,
636 bpy_lib_load_doc,
637};
638
639#ifdef __GNUC__
640# ifdef __clang__
641# pragma clang diagnostic pop
642# else
643# pragma GCC diagnostic pop
644# endif
645#endif
646
648{
649 if (PyType_Ready(&bpy_lib_Type) < 0) {
650 return -1;
651 }
652
653 return 0;
654}
Main * CTX_data_main(const bContext *C)
bool BKE_idtype_idcode_is_linkable(short idcode)
Definition idtype.cc:198
short BKE_idtype_idcode_iter_step(int *idtype_index)
Definition idtype.cc:376
const char * BKE_idtype_idcode_to_name_plural(short idcode)
Definition idtype.cc:172
void BKE_main_id_tag_all(Main *mainvar, int tag, bool value)
Definition lib_id.cc:1214
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:872
void BKE_reports_free(ReportList *reports)
Definition report.cc:70
void BKE_reports_clear(ReportList *reports)
Definition report.cc:82
void BKE_reports_init(ReportList *reports, int flag)
Definition report.cc:55
#define BLI_assert(a)
Definition BLI_assert.h:46
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
#define FILE_MAX
int BLI_path_normalize(char *path) ATTR_NONNULL(1)
#define BLI_path_cmp
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
#define POINTER_FROM_INT(i)
#define POINTER_AS_INT(i)
external readfile function prototypes.
void BLO_library_link_params_init(LibraryLink_Params *params, Main *bmain, int flag, int id_tag_extra)
Definition readfile.cc:4603
BlendHandle * BLO_blendhandle_from_file(const char *filepath, BlendFileReadReport *reports)
LinkNode * BLO_blendhandle_get_datablock_names(BlendHandle *bh, int ofblocktype, bool use_assets_only, int *r_tot_names)
@ ID_TAG_TEMP_MAIN
Definition DNA_ID.h:879
@ ID_TAG_PRE_EXISTING
Definition DNA_ID.h:834
@ ID_WS
@ FILE_RELPATH
@ FILE_LINK
@ FILE_ASSETS_ONLY
ReportList * reports
Definition WM_types.hh:1025
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMLoop * l
short BPy_reports_to_error(ReportList *reports, PyObject *exception, const bool clear)
struct bContext * BPY_context_get()
PyObject * self
PyMethodDef BPY_library_load_method_def
static void bpy_lib_dealloc(BPy_Library *self)
static PyObject * bpy_lib_exit(BPy_Library *self, PyObject *args)
static PyMethodDef bpy_lib_methods[]
PyDoc_STRVAR(bpy_lib_load_doc, ".. method:: load(" "filepath, " "link=False, " "relative=False, " "assets_only=False, " "create_liboverrides=False, " "reuse_liboverrides=False, " "create_liboverrides_runtime=False)\n" "\n" " Returns a context manager which exposes 2 library objects on entering.\n" " Each object has attributes matching bpy.data which are lists of strings to be linked.\n" "\n" " :arg filepath: The path to a blend file.\n" " :type filepath: str | bytes\n" " :arg link: When False reference to the original file is lost.\n" " :type link: bool\n" " :arg relative: When True the path is stored relative to the open blend file.\n" " :type relative: bool\n" " :arg assets_only: If True, only list data-blocks marked as assets.\n" " :type assets_only: bool\n" " :arg create_liboverrides: If True and ``link`` is True, liboverrides will\n" " be created for linked data.\n" " :type create_liboverrides: bool\n" " :arg reuse_liboverrides: If True and ``create_liboverride`` is True,\n" " search for existing liboverride first.\n" " :type reuse_liboverrides: bool\n" " :arg create_liboverrides_runtime: If True and ``create_liboverride`` is True,\n" " create (or search for existing) runtime liboverride.\n" " :type create_liboverrides_runtime: bool\n")
static PyObject * bpy_lib_enter(BPy_Library *self)
static PyObject * _bpy_names(BPy_Library *self, int blocktype)
static PyObject * bpy_lib_dir(BPy_Library *self)
static bool bpy_lib_exit_lapp_context_items_cb(BlendfileLinkAppendContext *lapp_context, BlendfileLinkAppendContextItem *item, LibExitLappContextItemsIterData &data)
static PyObject * bpy_lib_load(BPy_PropertyRNA *self, PyObject *args, PyObject *kw)
int BPY_library_load_type_ready()
static void bpy_lib_exit_warn_type(BPy_Library *self, PyObject *item)
static PyTypeObject bpy_lib_Type
static void bpy_lib_exit_warn_idname(BPy_Library *self, const char *name_plural, const char *idname)
PyObject * pyrna_struct_CreatePyObject(PointerRNA *ptr)
Definition bpy_rna.cc:8384
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
#define offsetof(t, d)
#define str(s)
#define INDEX_ID_MAX
int PyC_ParseUnicodeAsBytesAndSize(PyObject *o, void *p)
int PyC_ParseBool(PyObject *o, void *p)
header-only compatibility defines.
#define PY_ARG_PARSER_HEAD_COMPAT()
header-only utilities
#define PyTuple_SET_ITEMS(op_arg,...)
return ret
PointerRNA RNA_id_pointer_create(ID *id)
eBKELibLinkOverride liboverride_flags
BlendHandle * blo_handle
char abspath[FILE_MAX]
BlendFileReadReport bf_reports
PyObject * dict
ReportList reports
PyObject_HEAD char relpath[FILE_MAX]
Definition DNA_ID.h:404
i
Definition text_draw.cc:230