39 #include "../generic/py_capi_utils.h"
40 #include "../generic/python_utildefines.h"
43 #define USE_RNA_DATABLOCKS
45 #ifdef USE_RNA_DATABLOCKS
82 Py_XDECREF(
self->dict);
83 Py_TYPE(
self)->tp_free(
self);
87 PyVarObject_HEAD_INIT(
NULL, 0)
"bpy_lib",
112 PyObject_GenericGetAttr,
167 ".. method:: load(filepath, link=False, relative=False, assets_only=False)\n"
169 " Returns a context manager which exposes 2 library objects on entering.\n"
170 " Each object has attributes matching bpy.data which are lists of strings to be linked.\n"
172 " :arg filepath: The path to a blend file.\n"
173 " :type filepath: string\n"
174 " :arg link: When False reference to the original file is lost.\n"
175 " :type link: bool\n"
176 " :arg relative: When True the path is stored relative to the open blend file.\n"
177 " :type relative: bool\n"
178 " :arg assets_only: If True, only list data-blocks marked as assets.\n"
179 " :type assets_only: bool\n");
183 Main *bmain =
self->ptr.data;
185 const char *filepath =
NULL;
186 bool is_rel =
false, is_link =
false, use_assets_only =
false;
188 static const char *_keywords[] = {
"filepath",
"link",
"relative",
"assets_only",
NULL};
189 static _PyArg_Parser _parser = {
200 if (!_PyArg_ParseTupleAndKeywordsFast(args,
220 ret->bmain_is_temp = (bmain != bmain_base);
228 return (PyObject *)
ret;
239 list = PyList_New(totnames);
244 PyList_SET_ITEM(list,
counter, PyUnicode_FromString((
char *)
l->link));
257 PyObject *from_dict = _PyDict_NewPresized(
INDEX_ID_MAX);
262 memset(bf_reports, 0,
sizeof(*bf_reports));
269 PyErr_Format(PyExc_IOError,
"load: %s failed to open blend file",
self->abspath);
278 PyObject *
str = PyUnicode_FromString(name_plural);
281 PyDict_SetItem(
self->dict,
str, item = PyList_New(0));
283 PyDict_SetItem(from_dict,
str, item =
_bpy_names(
self, code));
297 self_from->
dict = from_dict;
300 ret = PyTuple_New(2);
310 const char *name_plural,
313 PyObject *exc, *val, *tb;
314 PyErr_Fetch(&exc, &val, &tb);
315 if (PyErr_WarnFormat(PyExc_UserWarning,
317 "load: '%s' does not contain %s[\"%s\"]",
322 if (PyErr_ExceptionMatches(PyExc_Warning)) {
323 PyErr_WriteUnraisable((PyObject *)
self);
326 PyErr_Restore(exc, val, tb);
331 PyObject *exc, *val, *tb;
332 PyErr_Fetch(&exc, &val, &tb);
333 if (PyErr_WarnFormat(PyExc_UserWarning,
335 "load: '%s' expected a string type, not a %.200s",
337 Py_TYPE(item)->tp_name)) {
339 if (PyErr_ExceptionMatches(PyExc_Warning)) {
340 PyErr_WriteUnraisable((PyObject *)
self);
343 PyErr_Restore(exc, val, tb);
375 PyObject *item_src = PyList_GET_ITEM(
data->py_list, py_list_index);
379 if (new_id !=
NULL) {
385 const char *item_idname = PyUnicode_AsUTF8(item_src);
390 py_item = Py_INCREF_RET(Py_None);
393 PyList_SET_ITEM(
data->py_list, py_list_index, py_item);
402 Main *bmain =
self->bmain;
403 const bool do_append = ((
self->flag &
FILE_LINK) == 0);
424 PyObject *ls = PyDict_GetItemString(
self->dict, name_plural);
426 if (ls ==
NULL || !PyList_Check(ls)) {
430 const Py_ssize_t
size = PyList_GET_SIZE(ls);
436 for (Py_ssize_t i = 0; i <
size; i++) {
437 PyObject *item_src = PyList_GET_ITEM(ls, i);
438 const char *item_idname = PyUnicode_AsUTF8(item_src);
444 if (item_idname !=
NULL) {
454 #ifdef USE_RNA_DATABLOCKS
456 PyObject *py_item = Py_INCREF_RET(Py_None);
457 PyList_SET_ITEM(ls, i, py_item);
470 #ifdef USE_RNA_DATABLOCKS
477 PyObject *ls = PyDict_GetItemString(
self->dict, name_plural);
479 if (ls ==
NULL || !PyList_Check(ls)) {
483 const Py_ssize_t
size = PyList_GET_SIZE(ls);
501 self->blo_handle =
NULL;
511 return PyDict_Keys(
self->dict);
517 METH_VARARGS | METH_KEYWORDS,
void BKE_blendfile_link_append_context_item_library_index_enable(struct BlendfileLinkAppendContext *lapp_context, struct BlendfileLinkAppendContextItem *item, int library_index)
struct ID * BKE_blendfile_link_append_context_item_newid_get(struct BlendfileLinkAppendContext *lapp_context, struct BlendfileLinkAppendContextItem *item)
struct BlendfileLinkAppendContextItem * BKE_blendfile_link_append_context_item_add(struct BlendfileLinkAppendContext *lapp_context, const char *idname, short idcode, void *userdata)
void BKE_blendfile_link(struct BlendfileLinkAppendContext *lapp_context, struct ReportList *reports)
void BKE_blendfile_link_append_context_library_add(struct BlendfileLinkAppendContext *lapp_context, const char *libname, struct BlendHandle *blo_handle)
void * BKE_blendfile_link_append_context_item_userdata_get(struct BlendfileLinkAppendContext *lapp_context, struct BlendfileLinkAppendContextItem *item)
void BKE_blendfile_link_append_context_free(struct BlendfileLinkAppendContext *lapp_context)
short BKE_blendfile_link_append_context_item_idcode_get(struct BlendfileLinkAppendContext *lapp_context, struct BlendfileLinkAppendContextItem *item)
void BKE_blendfile_link_append_context_item_foreach(struct BlendfileLinkAppendContext *lapp_context, BKE_BlendfileLinkAppendContexteItemFunction callback_function, eBlendfileLinkAppendForeachItemFlag flag, void *userdata)
@ BKE_BLENDFILE_LINK_APPEND_FOREACH_ITEM_FLAG_DO_DIRECT
BlendfileLinkAppendContext * BKE_blendfile_link_append_context_new(struct LibraryLink_Params *params)
void BKE_blendfile_append(struct BlendfileLinkAppendContext *lapp_context, struct ReportList *reports)
struct Main * CTX_data_main(const bContext *C)
const char * BKE_idtype_idcode_to_name_plural(short idcode)
short BKE_idtype_idcode_iter_step(int *index)
bool BKE_idtype_idcode_is_linkable(short idcode)
void BKE_main_id_tag_all(struct Main *mainvar, int tag, bool value)
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_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, size_t maxncpy) ATTR_NONNULL()
#define POINTER_FROM_INT(i)
#define POINTER_AS_INT(i)
external readfile function prototypes.
BlendHandle * BLO_blendhandle_from_file(const char *filepath, struct BlendFileReadReport *reports)
struct LinkNode * BLO_blendhandle_get_datablock_names(BlendHandle *bh, int ofblocktype, bool use_assets_only, int *r_tot_names)
struct BlendHandle BlendHandle
void BLO_library_link_params_init(struct LibraryLink_Params *params, struct Main *bmain, int flag, int id_tag_extra)
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 bool bpy_lib_exit_lapp_context_items_cb(BlendfileLinkAppendContext *lapp_context, BlendfileLinkAppendContextItem *item, void *userdata)
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)
ccl_gpu_kernel_postfix ccl_global int * counter
int PyC_ParseBool(PyObject *o, void *p)
#define PyTuple_SET_ITEMS(op_arg,...)
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
BlendFileReadReport bf_reports
PyObject_HEAD char relpath[FILE_MAX]
struct ReportList * reports