Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/intern/bpy_library_load.c
| Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | #endif | ||||
| NULL, /* PyObject *tp_cache; */ | NULL, /* PyObject *tp_cache; */ | ||||
| NULL, /* PyObject *tp_subclasses; */ | NULL, /* PyObject *tp_subclasses; */ | ||||
| NULL, /* PyObject *tp_weaklist; */ | NULL, /* PyObject *tp_weaklist; */ | ||||
| NULL, | NULL, | ||||
| }; | }; | ||||
| PyDoc_STRVAR( | PyDoc_STRVAR( | ||||
| bpy_lib_load_doc, | bpy_lib_load_doc, | ||||
| ".. method:: load(filepath, link=False, relative=False)\n" | ".. method:: load(filepath, link=False, assets_only=False, relative=False)\n" | ||||
| "\n" | "\n" | ||||
| " Returns a context manager which exposes 2 library objects on entering.\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" | " Each object has attributes matching bpy.data which are lists of strings to be linked.\n" | ||||
| "\n" | "\n" | ||||
| " :arg filepath: The path to a blend file.\n" | " :arg filepath: The path to a blend file.\n" | ||||
| " :type filepath: string\n" | " :type filepath: string\n" | ||||
| " :arg link: When False reference to the original file is lost.\n" | " :arg link: When False reference to the original file is lost.\n" | ||||
| " :type link: bool\n" | " :type link: bool\n" | ||||
| " :arg assets_only: If True, only list data-blocks marked as assets.\n" | |||||
| " :type assets_only: bool\n" | |||||
| " :arg relative: When True the path is stored relative to the open blend file.\n" | " :arg relative: When True the path is stored relative to the open blend file.\n" | ||||
| " :type relative: bool\n"); | " :type relative: bool\n"); | ||||
| static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject *kw) | static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject *kw) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(BPY_context_get()); | Main *bmain = CTX_data_main(BPY_context_get()); | ||||
| BPy_Library *ret; | BPy_Library *ret; | ||||
| const char *filename = NULL; | const char *filename = NULL; | ||||
| bool is_rel = false, is_link = false; | bool is_rel = false, is_link = false, use_assets_only = false; | ||||
| static const char *_keywords[] = {"filepath", "link", "relative", NULL}; | static const char *_keywords[] = {"filepath", "link", "relative", "assets_only", NULL}; | ||||
| static _PyArg_Parser _parser = {"s|O&O&:load", _keywords, 0}; | static _PyArg_Parser _parser = {"s|O&O&O&:load", _keywords, 0}; | ||||
| if (!_PyArg_ParseTupleAndKeywordsFast( | if (!_PyArg_ParseTupleAndKeywordsFast(args, | ||||
| args, kw, &_parser, &filename, PyC_ParseBool, &is_link, PyC_ParseBool, &is_rel)) { | kw, | ||||
| &_parser, | |||||
| &filename, | |||||
| PyC_ParseBool, | |||||
| &is_link, | |||||
| PyC_ParseBool, | |||||
| &is_rel, | |||||
| PyC_ParseBool, | |||||
| &use_assets_only)) { | |||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| ret = PyObject_New(BPy_Library, &bpy_lib_Type); | ret = PyObject_New(BPy_Library, &bpy_lib_Type); | ||||
| BLI_strncpy(ret->relpath, filename, sizeof(ret->relpath)); | BLI_strncpy(ret->relpath, filename, sizeof(ret->relpath)); | ||||
| BLI_strncpy(ret->abspath, filename, sizeof(ret->abspath)); | BLI_strncpy(ret->abspath, filename, sizeof(ret->abspath)); | ||||
| BLI_path_abs(ret->abspath, BKE_main_blendfile_path(bmain)); | BLI_path_abs(ret->abspath, BKE_main_blendfile_path(bmain)); | ||||
| ret->blo_handle = NULL; | ret->blo_handle = NULL; | ||||
| ret->flag = ((is_link ? FILE_LINK : 0) | (is_rel ? FILE_RELPATH : 0)); | ret->flag = ((is_link ? FILE_LINK : 0) | (is_rel ? FILE_RELPATH : 0) | | ||||
| (use_assets_only ? FILE_ASSETS_ONLY : 0)); | |||||
| ret->dict = _PyDict_NewPresized(MAX_LIBARRAY); | ret->dict = _PyDict_NewPresized(MAX_LIBARRAY); | ||||
| return (PyObject *)ret; | return (PyObject *)ret; | ||||
| } | } | ||||
| static PyObject *_bpy_names(BPy_Library *self, int blocktype) | static PyObject *_bpy_names(BPy_Library *self, int blocktype) | ||||
| { | { | ||||
| PyObject *list; | PyObject *list; | ||||
| LinkNode *l, *names; | LinkNode *l, *names; | ||||
| int totnames; | int totnames; | ||||
| names = BLO_blendhandle_get_datablock_names(self->blo_handle, blocktype, &totnames); | names = BLO_blendhandle_get_datablock_names( | ||||
| self->blo_handle, blocktype, (self->flag & FILE_ASSETS_ONLY) != 0, &totnames); | |||||
| list = PyList_New(totnames); | list = PyList_New(totnames); | ||||
| if (names) { | if (names) { | ||||
| int counter = 0; | int counter = 0; | ||||
| for (l = names; l; l = l->next) { | for (l = names; l; l = l->next) { | ||||
| PyList_SET_ITEM(list, counter, PyUnicode_FromString((char *)l->link)); | PyList_SET_ITEM(list, counter, PyUnicode_FromString((char *)l->link)); | ||||
| counter++; | counter++; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 258 Lines • Show Last 20 Lines | |||||