45#define USE_RNA_DATABLOCKS
47#ifdef USE_RNA_DATABLOCKS
79#if (defined(__GNUC__) && !defined(__clang__))
80# pragma GCC diagnostic push
81# pragma GCC diagnostic ignored "-Wcast-function-type"
91#if (defined(__GNUC__) && !defined(__clang__))
92# pragma GCC diagnostic pop
97 Py_XDECREF(
self->dict);
102 PyVarObject_HEAD_INIT(
nullptr, 0)
118 PyObject_GenericGetAttr,
160 "assets_only=False, "
161 "create_liboverrides=False, "
162 "reuse_liboverrides=False, "
163 "create_liboverrides_runtime=False)\n"
165 " Returns a context manager which exposes 2 library objects on entering.\n"
166 " Each object has attributes matching bpy.data which are lists of strings to be linked.\n"
168 " :arg filepath: The path to a blend file.\n"
169 " :type filepath: str | bytes\n"
170 " :arg link: When False reference to the original file is lost.\n"
171 " :type link: bool\n"
172 " :arg relative: When True the path is stored relative to the open blend file.\n"
173 " :type relative: bool\n"
174 " :arg assets_only: If True, only list data-blocks marked as assets.\n"
175 " :type assets_only: bool\n"
176 " :arg create_liboverrides: If True and ``link`` is True, liboverrides will\n"
177 " be created for linked data.\n"
178 " :type create_liboverrides: bool\n"
179 " :arg reuse_liboverrides: If True and ``create_liboverride`` is True,\n"
180 " search for existing liboverride first.\n"
181 " :type reuse_liboverrides: bool\n"
182 " :arg create_liboverrides_runtime: If True and ``create_liboverride`` is True,\n"
183 " create (or search for existing) runtime liboverride.\n"
184 " :type create_liboverrides_runtime: bool\n");
191 bool is_rel =
false, is_link =
false, use_assets_only =
false;
192 bool create_liboverrides =
false, reuse_liboverrides =
false,
193 create_liboverrides_runtime =
false;
195 static const char *_keywords[] = {
200 "create_liboverrides",
201 "reuse_liboverrides",
202 "create_liboverrides_runtime",
205 static _PyArg_Parser _parser = {
220 if (!_PyArg_ParseTupleAndKeywordsFast(args,
232 &create_liboverrides,
236 &create_liboverrides_runtime))
241 if (!is_link && create_liboverrides) {
242 PyErr_SetString(PyExc_ValueError,
"`link` is False but `create_liboverrides` is True");
245 if (!create_liboverrides && reuse_liboverrides) {
246 PyErr_SetString(PyExc_ValueError,
247 "`create_liboverrides` is False but `reuse_liboverrides` is True");
250 if (!create_liboverrides && create_liboverrides_runtime) {
251 PyErr_SetString(PyExc_ValueError,
252 "`create_liboverrides` is False but `create_liboverrides_runtime` is True");
265 ret->bmain_is_temp = (bmain != bmain_base);
267 ret->blo_handle =
nullptr;
270 ret->create_liboverrides = create_liboverrides;
272 create_liboverrides ?
279 return (PyObject *)
ret;
290 list = PyList_New(totnames);
295 PyList_SET_ITEM(list, counter, PyUnicode_FromString((
char *)
l->link));
308 PyObject *from_dict = _PyDict_NewPresized(
INDEX_ID_MAX);
313 memset(bf_reports, 0,
sizeof(*bf_reports));
318 if (
self->blo_handle ==
nullptr) {
320 PyErr_Format(PyExc_IOError,
"load: %s failed to open blend file",
self->abspath);
329 PyObject *
str = PyUnicode_FromString(name_plural);
332 PyDict_SetItem(
self->dict,
str, item = PyList_New(0));
350 self_from->
dict = from_dict;
353 ret = PyTuple_New(2);
363 const char *name_plural,
366 PyObject *exc, *val, *tb;
367 PyErr_Fetch(&exc, &val, &tb);
368 if (PyErr_WarnFormat(PyExc_UserWarning,
370 "load: '%s' does not contain %s[\"%s\"]",
376 if (PyErr_ExceptionMatches(PyExc_Warning)) {
377 PyErr_WriteUnraisable((PyObject *)
self);
380 PyErr_Restore(exc, val, tb);
385 PyObject *exc, *val, *tb;
386 PyErr_Fetch(&exc, &val, &tb);
387 if (PyErr_WarnFormat(PyExc_UserWarning,
389 "load: '%s' expected a string type, not a %.200s",
391 Py_TYPE(item)->tp_name))
394 if (PyErr_ExceptionMatches(PyExc_Warning)) {
395 PyErr_WriteUnraisable((PyObject *)
self);
398 PyErr_Restore(exc, val, tb);
422 ID *liboverride_id = data.py_library->create_liboverrides ?
427 BLI_assert(py_list_index < data.py_list_size);
432 PyObject *item_src = PyList_GET_ITEM(data.py_list, py_list_index);
436 if (liboverride_id !=
nullptr) {
440 else if (new_id !=
nullptr) {
445 const char *item_idname = PyUnicode_AsUTF8(item_src);
450 py_item = Py_NewRef(Py_None);
453 PyList_SET_ITEM(data.py_list, py_list_index, py_item);
464 const bool create_liboverrides =
self->create_liboverrides;
467 BLI_assert(!do_append || !create_liboverrides);
480 self->blo_handle =
nullptr;
490 PyObject *ls = PyDict_GetItemString(
self->dict, name_plural);
492 if (ls ==
nullptr || !PyList_Check(ls)) {
496 const Py_ssize_t size = PyList_GET_SIZE(ls);
502 for (Py_ssize_t i = 0; i <
size; i++) {
503 PyObject *item_src = PyList_GET_ITEM(ls, i);
504 const char *item_idname = PyUnicode_AsUTF8(item_src);
510 if (item_idname !=
nullptr) {
520#ifdef USE_RNA_DATABLOCKS
522 PyObject *py_item = Py_NewRef(Py_None);
523 PyList_SET_ITEM(ls, i, py_item);
536 else if (create_liboverrides) {
543#ifdef USE_RNA_DATABLOCKS
550 PyObject *ls = PyDict_GetItemString(
self->dict, name_plural);
552 if (ls ==
nullptr || !PyList_Check(ls)) {
556 const Py_ssize_t size = PyList_GET_SIZE(ls);
564 iter_data.
idcode = idcode;
565 iter_data.py_library =
self;
566 iter_data.py_list = ls;
567 iter_data.py_list_size =
size;
588 return PyDict_Keys(
self->dict);
591#if (defined(__GNUC__) && !defined(__clang__))
592# pragma GCC diagnostic push
593# pragma GCC diagnostic ignored "-Wcast-function-type"
599 METH_VARARGS | METH_KEYWORDS,
603#if (defined(__GNUC__) && !defined(__clang__))
604# pragma GCC diagnostic pop
void BKE_blendfile_link_append_context_finalize(BlendfileLinkAppendContext *lapp_context)
void BKE_blendfile_link_append_context_item_foreach(BlendfileLinkAppendContext *lapp_context, blender::FunctionRef< bool(BlendfileLinkAppendContext *lapp_context, BlendfileLinkAppendContextItem *item)> callback_function, eBlendfileLinkAppendForeachItemFlag flag)
@ BKE_LIBLINK_OVERRIDE_USE_EXISTING_LIBOVERRIDES
@ BKE_LIBLINK_OVERRIDE_CREATE_RUNTIME
@ BKE_LIBLINK_OVERRIDE_INIT
void BKE_blendfile_link(BlendfileLinkAppendContext *lapp_context, ReportList *reports)
void BKE_blendfile_link_append_context_library_add(BlendfileLinkAppendContext *lapp_context, const char *libname, BlendHandle *blo_handle)
BlendfileLinkAppendContextItem * BKE_blendfile_link_append_context_item_add(BlendfileLinkAppendContext *lapp_context, const char *idname, short idcode, void *userdata)
void BKE_blendfile_link_append_context_free(BlendfileLinkAppendContext *lapp_context)
void BKE_blendfile_append(BlendfileLinkAppendContext *lapp_context, ReportList *reports)
void BKE_blendfile_override(BlendfileLinkAppendContext *lapp_context, const eBKELibLinkOverride flags, ReportList *reports)
void BKE_blendfile_link_append_context_item_library_index_enable(BlendfileLinkAppendContext *lapp_context, BlendfileLinkAppendContextItem *item, int library_index)
BlendfileLinkAppendContext * BKE_blendfile_link_append_context_new(LibraryLink_Params *params)
short BKE_blendfile_link_append_context_item_idcode_get(BlendfileLinkAppendContext *lapp_context, BlendfileLinkAppendContextItem *item)
ID * BKE_blendfile_link_append_context_item_liboverrideid_get(BlendfileLinkAppendContext *lapp_context, BlendfileLinkAppendContextItem *item)
@ BKE_BLENDFILE_LINK_APPEND_FOREACH_ITEM_FLAG_DO_DIRECT
void * BKE_blendfile_link_append_context_item_userdata_get(BlendfileLinkAppendContext *lapp_context, BlendfileLinkAppendContextItem *item)
void BKE_blendfile_link_append_context_init_done(BlendfileLinkAppendContext *lapp_context)
ID * BKE_blendfile_link_append_context_item_newid_get(BlendfileLinkAppendContext *lapp_context, BlendfileLinkAppendContextItem *item)
Main * CTX_data_main(const bContext *C)
bool BKE_idtype_idcode_is_linkable(short idcode)
short BKE_idtype_idcode_iter_step(int *idtype_index)
const char * BKE_idtype_idcode_to_name_plural(short idcode)
void BKE_main_id_tag_all(Main *mainvar, int tag, bool value)
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
void BKE_reports_free(ReportList *reports)
void BKE_reports_clear(ReportList *reports)
void BKE_reports_init(ReportList *reports, int flag)
void BLI_linklist_freeN(LinkNode *list)
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
#define STRNCPY(dst, src)
#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)
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)
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMLoop * l
short BPy_reports_to_error(ReportList *reports, PyObject *exception, const bool clear)
struct bContext * BPY_context_get(void)
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)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
int PyC_ParseUnicodeAsBytesAndSize(PyObject *o, void *p)
int PyC_ParseBool(PyObject *o, void *p)
header-only compatibility defines.
#define PY_ARG_PARSER_HEAD_COMPAT()
#define PyTuple_SET_ITEMS(op_arg,...)
PointerRNA RNA_id_pointer_create(ID *id)
eBKELibLinkOverride liboverride_flags
BlendFileReadReport bf_reports
PyObject_HEAD char relpath[FILE_MAX]