52 #include "../generic/py_capi_utils.h"
53 #include "../generic/python_utildefines.h"
56 #define USE_RNA_DATABLOCKS
58 #ifdef USE_RNA_DATABLOCKS
91 Py_XDECREF(
self->dict);
92 Py_TYPE(
self)->tp_free(
self);
96 PyVarObject_HEAD_INIT(
NULL, 0)
"bpy_lib",
121 PyObject_GenericGetAttr,
176 ".. method:: load(filepath, link=False, relative=False, assets_only=False)\n"
178 " Returns a context manager which exposes 2 library objects on entering.\n"
179 " Each object has attributes matching bpy.data which are lists of strings to be linked.\n"
181 " :arg filepath: The path to a blend file.\n"
182 " :type filepath: string\n"
183 " :arg link: When False reference to the original file is lost.\n"
184 " :type link: bool\n"
185 " :arg relative: When True the path is stored relative to the open blend file.\n"
186 " :type relative: bool\n"
187 " :arg assets_only: If True, only list data-blocks marked as assets.\n"
188 " :type assets_only: bool\n");
192 Main *bmain =
self->ptr.data;
194 const char *filename =
NULL;
195 bool is_rel =
false, is_link =
false, use_assets_only =
false;
197 static const char *_keywords[] = {
"filepath",
"link",
"relative",
"assets_only",
NULL};
198 static _PyArg_Parser _parser = {
"s|O&O&O&:load", _keywords, 0};
199 if (!_PyArg_ParseTupleAndKeywordsFast(args,
219 ret->bmain_is_temp = (bmain != bmain_base);
227 return (PyObject *)
ret;
238 list = PyList_New(totnames);
243 PyList_SET_ITEM(list, counter, PyUnicode_FromString((
char *)
l->link));
256 PyObject *from_dict = _PyDict_NewPresized(
INDEX_ID_MAX);
265 PyErr_Format(PyExc_IOError,
"load: %s failed to open blend file",
self->abspath);
274 PyObject *
str = PyUnicode_FromString(name_plural);
277 PyDict_SetItem(
self->dict,
str, item = PyList_New(0));
279 PyDict_SetItem(from_dict,
str, item =
_bpy_names(
self, code));
293 self_from->
dict = from_dict;
296 ret = PyTuple_New(2);
306 const char *name_plural,
309 PyObject *exc, *val, *tb;
310 PyErr_Fetch(&exc, &val, &tb);
311 if (PyErr_WarnFormat(PyExc_UserWarning,
313 "load: '%s' does not contain %s[\"%s\"]",
318 if (PyErr_ExceptionMatches(PyExc_Warning)) {
319 PyErr_WriteUnraisable((PyObject *)
self);
322 PyErr_Restore(exc, val, tb);
327 PyObject *exc, *val, *tb;
328 PyErr_Fetch(&exc, &val, &tb);
329 if (PyErr_WarnFormat(PyExc_UserWarning,
331 "load: '%s' expected a string type, not a %.200s",
333 Py_TYPE(item)->tp_name)) {
335 if (PyErr_ExceptionMatches(PyExc_Warning)) {
336 PyErr_WriteUnraisable((PyObject *)
self);
339 PyErr_Restore(exc, val, tb);
344 Main *bmain =
self->bmain;
347 const bool do_append = ((
self->flag &
FILE_LINK) == 0);
359 int idcode_step = 0, idcode;
363 PyObject *ls = PyDict_GetItemString(
self->dict, name_plural);
365 if (ls && PyList_Check(ls)) {
367 const Py_ssize_t
size = PyList_GET_SIZE(ls);
370 for (i = 0; i <
size; i++) {
371 PyObject *item_src = PyList_GET_ITEM(ls, i);
373 const char *item_idname = PyUnicode_AsUTF8(item_src);
379 mainl, &(
self->blo_handle), idcode, item_idname, &liblink_params);
382 if (
self->bmain_is_temp) {
387 #ifdef USE_RNA_DATABLOCKS
389 item_dst = PyCapsule_New((
void *)
id,
NULL,
NULL);
399 item_dst = Py_INCREF_RET(Py_None);
408 item_dst = Py_INCREF_RET(Py_None);
413 PyList_SET_ITEM(ls, i, item_dst);
423 self->blo_handle =
NULL;
431 self->blo_handle =
NULL;
450 #ifdef USE_RNA_DATABLOCKS
452 int idcode_step = 0, idcode;
456 PyObject *ls = PyDict_GetItemString(
self->dict, name_plural);
457 if (ls && PyList_Check(ls)) {
458 const Py_ssize_t
size = PyList_GET_SIZE(ls);
462 for (i = 0; i <
size; i++) {
463 item = PyList_GET_ITEM(ls, i);
464 if (PyCapsule_CheckExact(item)) {
468 id = PyCapsule_GetPointer(item,
NULL);
474 PyList_SET_ITEM(ls, i, item);
489 return PyDict_Keys(
self->dict);
495 METH_VARARGS | METH_KEYWORDS,
struct Main * CTX_data_main(const bContext *C)
const char * BKE_idtype_idcode_to_name_plural(const short idcode)
bool BKE_idtype_idcode_is_linkable(const short idcode)
short BKE_idtype_idcode_iter_step(int *index)
void BKE_main_id_tag_all(struct Main *mainvar, const int tag, const bool value)
void BKE_main_lib_objects_recalc_all(struct Main *bmain)
void BKE_library_make_local(struct Main *bmain, const struct Library *lib, struct GHash *old_to_new_ids, const bool untagged_only, const bool set_fake)
const char * BKE_main_blendfile_path(const struct Main *bmain) ATTR_NONNULL()
void BKE_reports_clear(ReportList *reports)
void BKE_reports_init(ReportList *reports, int flag)
void * BLI_ghash_lookup_default(GHash *gh, const void *key, void *val_default) ATTR_WARN_UNUSED_RESULT
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
GHash * BLI_ghash_ptr_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_linklist_freeN(LinkNode *list)
bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL()
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
external readfile function prototypes.
void BLO_library_link_params_init(struct LibraryLink_Params *params, struct Main *bmain, const int flag, const int id_tag_extra)
struct ID * BLO_library_link_named_part(struct Main *mainl, BlendHandle **bh, const short idcode, const char *name, const struct LibraryLink_Params *params)
struct BlendHandle BlendHandle
struct Main * BLO_library_link_begin(BlendHandle **bh, const char *filepath, const struct LibraryLink_Params *params)
void BLO_library_link_end(struct Main *mainl, BlendHandle **bh, const struct LibraryLink_Params *params)
struct LinkNode * BLO_blendhandle_get_datablock_names(BlendHandle *bh, int ofblocktype, const bool use_assets_only, int *r_tot_names)
BlendHandle * BLO_blendhandle_from_file(const char *filepath, struct ReportList *reports)
void BLO_blendhandle_close(BlendHandle *bh)
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 PyMethodDef bpy_lib_methods[]
PyDoc_STRVAR(bpy_lib_load_doc, ".. method:: load(filepath, link=False, relative=False, assets_only=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: string\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")
static PyObject * bpy_lib_enter(BPy_Library *self)
static PyObject * bpy_lib_exit(BPy_Library *self, PyObject *args)
static PyObject * bpy_lib_dir(BPy_Library *self)
int BPY_library_load_type_ready(void)
static PyObject * _bpy_names(BPy_Library *self, int blocktype)
static void bpy_lib_exit_warn_type(BPy_Library *self, PyObject *item)
static PyTypeObject bpy_lib_Type
static PyObject * bpy_lib_load(BPy_PropertyRNA *self, PyObject *args, PyObject *kwds)
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)
int PyC_ParseBool(PyObject *o, void *p)
#define PyTuple_SET_ITEMS(op_arg,...)
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
PyObject_HEAD char relpath[FILE_MAX]