library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
/*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2016-03-03 13:11:07 +11:00
|
|
|
/** \file blender/python/intern/bpy_library_load.c
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
* \ingroup pythonintern
|
2011-11-05 08:21:12 +00:00
|
|
|
*
|
|
|
|
* This file exposed blend file library appending/linking to python, typically
|
|
|
|
* this would be done via RNA api but in this case a hand written python api
|
|
|
|
* allows us to use pythons context manager (__enter__ and __exit__).
|
|
|
|
*
|
2011-11-05 08:40:07 +00:00
|
|
|
* Everything here is exposed via bpy.data.libraries.load(...) which returns
|
|
|
|
* a context manager.
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Python.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2012-07-08 06:00:27 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
#include "BLI_string.h"
|
|
|
|
#include "BLI_linklist.h"
|
|
|
|
#include "BLI_path_util.h"
|
|
|
|
|
2013-04-05 17:56:54 +00:00
|
|
|
#include "BLO_readfile.h"
|
|
|
|
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BKE_library.h"
|
|
|
|
#include "BKE_idcode.h"
|
|
|
|
#include "BKE_report.h"
|
2011-08-05 05:26:19 +00:00
|
|
|
#include "BKE_context.h"
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
|
|
|
#include "DNA_space_types.h" /* FILE_LINK, FILE_RELPATH */
|
|
|
|
|
|
|
|
#include "bpy_util.h"
|
2012-09-15 01:52:28 +00:00
|
|
|
#include "bpy_library.h"
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
2015-08-04 18:34:20 +10:00
|
|
|
#include "../generic/py_capi_utils.h"
|
2015-01-06 16:42:22 +11:00
|
|
|
#include "../generic/python_utildefines.h"
|
|
|
|
|
2013-04-05 17:56:54 +00:00
|
|
|
/* nifty feature. swap out strings for RNA data */
|
|
|
|
#define USE_RNA_DATABLOCKS
|
|
|
|
|
2011-05-24 15:21:14 +00:00
|
|
|
#ifdef USE_RNA_DATABLOCKS
|
|
|
|
# include "bpy_rna.h"
|
|
|
|
# include "RNA_access.h"
|
|
|
|
#endif
|
|
|
|
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
typedef struct {
|
2012-03-16 21:39:56 +00:00
|
|
|
PyObject_HEAD /* required python macro */
|
2011-10-15 14:14:22 +00:00
|
|
|
/* collection iterator specific parts */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
char relpath[FILE_MAX];
|
|
|
|
char abspath[FILE_MAX]; /* absolute path */
|
|
|
|
BlendHandle *blo_handle;
|
|
|
|
int flag;
|
|
|
|
PyObject *dict;
|
|
|
|
} BPy_Library;
|
|
|
|
|
|
|
|
static PyObject *bpy_lib_load(PyObject *self, PyObject *args, PyObject *kwds);
|
|
|
|
static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *args);
|
|
|
|
static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *args);
|
2011-03-14 01:00:41 +00:00
|
|
|
static PyObject *bpy_lib_dir(BPy_Library *self);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
static PyMethodDef bpy_lib_methods[] = {
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
{"__enter__", (PyCFunction)bpy_lib_enter, METH_NOARGS},
|
2011-11-05 08:40:07 +00:00
|
|
|
{"__exit__", (PyCFunction)bpy_lib_exit, METH_VARARGS},
|
|
|
|
{"__dir__", (PyCFunction)bpy_lib_dir, METH_NOARGS},
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
{NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void bpy_lib_dealloc(BPy_Library *self)
|
|
|
|
{
|
|
|
|
Py_XDECREF(self->dict);
|
|
|
|
Py_TYPE(self)->tp_free(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
static PyTypeObject bpy_lib_Type = {
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2012-03-26 20:41:54 +00:00
|
|
|
"bpy_lib", /* tp_name */
|
|
|
|
sizeof(BPy_Library), /* tp_basicsize */
|
|
|
|
0, /* tp_itemsize */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
/* methods */
|
2012-03-26 20:41:54 +00:00
|
|
|
(destructor)bpy_lib_dealloc, /* tp_dealloc */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
NULL, /* printfunc tp_print; */
|
2012-03-26 20:41:54 +00:00
|
|
|
NULL, /* getattrfunc tp_getattr; */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
NULL, /* setattrfunc tp_setattr; */
|
2012-03-26 20:41:54 +00:00
|
|
|
NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */
|
|
|
|
NULL, /* tp_repr */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
|
|
|
/* Method suites for standard classes */
|
|
|
|
|
2012-03-26 20:41:54 +00:00
|
|
|
NULL, /* PyNumberMethods *tp_as_number; */
|
|
|
|
NULL, /* PySequenceMethods *tp_as_sequence; */
|
|
|
|
NULL, /* PyMappingMethods *tp_as_mapping; */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
|
|
|
/* More standard operations (here for binary compatibility) */
|
|
|
|
|
2012-03-26 20:41:54 +00:00
|
|
|
NULL, /* hashfunc tp_hash; */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
NULL, /* ternaryfunc tp_call; */
|
|
|
|
NULL, /* reprfunc tp_str; */
|
|
|
|
|
|
|
|
/* will only use these if this is a subtype of a py class */
|
2012-03-26 20:41:54 +00:00
|
|
|
NULL /*PyObject_GenericGetAttr is assigned later */, /* getattrofunc tp_getattro; */
|
|
|
|
NULL, /* setattrofunc tp_setattro; */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
|
|
|
/* Functions to access object as input/output buffer */
|
|
|
|
NULL, /* PyBufferProcs *tp_as_buffer; */
|
|
|
|
|
2012-03-26 20:41:54 +00:00
|
|
|
/*** Flags to define presence of optional/expanded features ***/
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
|
|
|
|
2012-03-26 20:41:54 +00:00
|
|
|
NULL, /* char *tp_doc; Documentation string */
|
|
|
|
/*** Assigned meaning in release 2.0 ***/
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
/* call function for all accessible objects */
|
|
|
|
NULL, /* traverseproc tp_traverse; */
|
|
|
|
|
|
|
|
/* delete references to contained objects */
|
|
|
|
NULL, /* inquiry tp_clear; */
|
|
|
|
|
2012-03-26 20:41:54 +00:00
|
|
|
/*** Assigned meaning in release 2.1 ***/
|
|
|
|
/*** rich comparisons ***/
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
NULL, /* subclassed */ /* richcmpfunc tp_richcompare; */
|
|
|
|
|
2012-03-26 20:41:54 +00:00
|
|
|
/*** weak reference enabler ***/
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
0,
|
2012-03-26 20:41:54 +00:00
|
|
|
/*** Added in release 2.2 ***/
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
/* Iterators */
|
2012-03-26 20:41:54 +00:00
|
|
|
NULL, /* getiterfunc tp_iter; */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
NULL, /* iternextfunc tp_iternext; */
|
|
|
|
|
2012-03-26 20:41:54 +00:00
|
|
|
/*** Attribute descriptor and subclassing stuff ***/
|
|
|
|
bpy_lib_methods, /* struct PyMethodDef *tp_methods; */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
NULL, /* struct PyMemberDef *tp_members; */
|
2012-03-26 20:41:54 +00:00
|
|
|
NULL, /* struct PyGetSetDef *tp_getset; */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
NULL, /* struct _typeobject *tp_base; */
|
|
|
|
NULL, /* PyObject *tp_dict; */
|
|
|
|
NULL, /* descrgetfunc tp_descr_get; */
|
|
|
|
NULL, /* descrsetfunc tp_descr_set; */
|
2012-03-26 20:41:54 +00:00
|
|
|
offsetof(BPy_Library, dict), /* long tp_dictoffset; */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
NULL, /* initproc tp_init; */
|
|
|
|
NULL, /* allocfunc tp_alloc; */
|
2012-03-26 20:41:54 +00:00
|
|
|
NULL, /* newfunc tp_new; */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
/* Low-level free-memory routine */
|
|
|
|
NULL, /* freefunc tp_free; */
|
|
|
|
/* For PyObject_IS_GC */
|
|
|
|
NULL, /* inquiry tp_is_gc; */
|
2012-03-26 20:41:54 +00:00
|
|
|
NULL, /* PyObject *tp_bases; */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
/* method resolution order */
|
|
|
|
NULL, /* PyObject *tp_mro; */
|
|
|
|
NULL, /* PyObject *tp_cache; */
|
|
|
|
NULL, /* PyObject *tp_subclasses; */
|
|
|
|
NULL, /* PyObject *tp_weaklist; */
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2011-05-24 16:05:51 +00:00
|
|
|
PyDoc_STRVAR(bpy_lib_load_doc,
|
2012-06-04 20:11:09 +00:00
|
|
|
".. method:: load(filepath, link=False, relative=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"
|
|
|
|
);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
|
|
|
|
{
|
2011-12-26 12:26:11 +00:00
|
|
|
static const char *kwlist[] = {"filepath", "link", "relative", NULL};
|
2016-07-14 21:00:05 +10:00
|
|
|
Main *bmain = CTX_data_main(BPy_GetContext());
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
BPy_Library *ret;
|
2012-03-16 21:39:56 +00:00
|
|
|
const char *filename = NULL;
|
2015-08-04 18:34:20 +10:00
|
|
|
bool is_rel = false, is_link = false;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTupleAndKeywords(
|
|
|
|
args, kwds,
|
|
|
|
"s|O&O&:load", (char **)kwlist,
|
|
|
|
&filename,
|
|
|
|
PyC_ParseBool, &is_link,
|
|
|
|
PyC_ParseBool, &is_rel))
|
|
|
|
{
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
return NULL;
|
2015-08-04 18:34:20 +10:00
|
|
|
}
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
ret = PyObject_New(BPy_Library, &bpy_lib_Type);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
2011-03-14 10:31:50 +00:00
|
|
|
BLI_strncpy(ret->relpath, filename, sizeof(ret->relpath));
|
|
|
|
BLI_strncpy(ret->abspath, filename, sizeof(ret->abspath));
|
2016-07-14 21:00:05 +10:00
|
|
|
BLI_path_abs(ret->abspath, bmain->name);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
ret->blo_handle = NULL;
|
2012-03-16 21:39:56 +00:00
|
|
|
ret->flag = ((is_link ? FILE_LINK : 0) |
|
|
|
|
(is_rel ? FILE_RELPATH : 0));
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
ret->dict = PyDict_New();
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
|
|
|
return (PyObject *)ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *_bpy_names(BPy_Library *self, int blocktype)
|
|
|
|
{
|
|
|
|
PyObject *list;
|
|
|
|
LinkNode *l, *names;
|
|
|
|
int totnames;
|
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
names = BLO_blendhandle_get_datablock_names(self->blo_handle, blocktype, &totnames);
|
2016-07-14 21:00:05 +10:00
|
|
|
list = PyList_New(totnames);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (names) {
|
2011-12-26 12:26:11 +00:00
|
|
|
int counter = 0;
|
|
|
|
for (l = names; l; l = l->next) {
|
2011-06-02 08:29:16 +00:00
|
|
|
PyList_SET_ITEM(list, counter, PyUnicode_FromString((char *)l->link));
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
counter++;
|
|
|
|
}
|
2012-03-26 20:41:54 +00:00
|
|
|
BLI_linklist_free(names, free); /* free linklist *and* each node's data */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *UNUSED(args))
|
|
|
|
{
|
|
|
|
PyObject *ret;
|
|
|
|
BPy_Library *self_from;
|
2011-12-26 12:26:11 +00:00
|
|
|
PyObject *from_dict = PyDict_New();
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
ReportList reports;
|
|
|
|
|
|
|
|
BKE_reports_init(&reports, RPT_STORE);
|
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
self->blo_handle = BLO_blendhandle_from_file(self->abspath, &reports);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (self->blo_handle == NULL) {
|
2013-01-07 05:26:12 +00:00
|
|
|
if (BPy_reports_to_error(&reports, PyExc_IOError, true) != -1) {
|
2011-04-30 13:58:31 +00:00
|
|
|
PyErr_Format(PyExc_IOError,
|
|
|
|
"load: %s failed to open blend file",
|
|
|
|
self->abspath);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else {
|
2011-12-26 12:26:11 +00:00
|
|
|
int i = 0, code;
|
|
|
|
while ((code = BKE_idcode_iter_step(&i))) {
|
2011-10-13 01:29:08 +00:00
|
|
|
if (BKE_idcode_is_linkable(code)) {
|
2011-12-26 12:26:11 +00:00
|
|
|
const char *name_plural = BKE_idcode_to_name_plural(code);
|
|
|
|
PyObject *str = PyUnicode_FromString(name_plural);
|
2016-07-14 17:28:28 +10:00
|
|
|
PyObject *item;
|
|
|
|
|
|
|
|
PyDict_SetItem(self->dict, str, item = PyList_New(0));
|
|
|
|
Py_DECREF(item);
|
|
|
|
PyDict_SetItem(from_dict, str, item = _bpy_names(self, code));
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
Py_DECREF(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a dummy */
|
2011-12-26 12:26:11 +00:00
|
|
|
self_from = PyObject_New(BPy_Library, &bpy_lib_Type);
|
2011-11-30 06:15:35 +00:00
|
|
|
BLI_strncpy(self_from->relpath, self->relpath, sizeof(self_from->relpath));
|
|
|
|
BLI_strncpy(self_from->abspath, self->abspath, sizeof(self_from->abspath));
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
self_from->blo_handle = NULL;
|
|
|
|
self_from->flag = 0;
|
|
|
|
self_from->dict = from_dict; /* owns the dict */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
|
|
|
/* return pair */
|
2011-12-26 12:26:11 +00:00
|
|
|
ret = PyTuple_New(2);
|
2015-01-06 16:42:22 +11:00
|
|
|
PyTuple_SET_ITEMS(ret,
|
|
|
|
(PyObject *)self_from,
|
|
|
|
(PyObject *)self);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
Py_INCREF(self);
|
|
|
|
|
|
|
|
BKE_reports_clear(&reports);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-24 15:21:14 +00:00
|
|
|
static void bpy_lib_exit_warn_idname(BPy_Library *self, const char *name_plural, const char *idname)
|
|
|
|
{
|
|
|
|
PyObject *exc, *val, *tb;
|
|
|
|
PyErr_Fetch(&exc, &val, &tb);
|
|
|
|
if (PyErr_WarnFormat(PyExc_UserWarning, 1,
|
2011-11-05 08:40:07 +00:00
|
|
|
"load: '%s' does not contain %s[\"%s\"]",
|
2012-05-20 19:49:27 +00:00
|
|
|
self->abspath, name_plural, idname))
|
|
|
|
{
|
2011-05-24 15:21:14 +00:00
|
|
|
/* Spurious errors can appear at shutdown */
|
|
|
|
if (PyErr_ExceptionMatches(PyExc_Warning)) {
|
|
|
|
PyErr_WriteUnraisable((PyObject *)self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PyErr_Restore(exc, val, tb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bpy_lib_exit_warn_type(BPy_Library *self, PyObject *item)
|
|
|
|
{
|
|
|
|
PyObject *exc, *val, *tb;
|
|
|
|
PyErr_Fetch(&exc, &val, &tb);
|
|
|
|
if (PyErr_WarnFormat(PyExc_UserWarning, 1,
|
2011-11-05 08:40:07 +00:00
|
|
|
"load: '%s' expected a string type, not a %.200s",
|
2012-05-20 19:49:27 +00:00
|
|
|
self->abspath, Py_TYPE(item)->tp_name))
|
|
|
|
{
|
2011-05-24 15:21:14 +00:00
|
|
|
/* Spurious errors can appear at shutdown */
|
|
|
|
if (PyErr_ExceptionMatches(PyExc_Warning)) {
|
|
|
|
PyErr_WriteUnraisable((PyObject *)self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PyErr_Restore(exc, val, tb);
|
|
|
|
}
|
|
|
|
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
|
|
|
|
{
|
2011-12-26 12:26:11 +00:00
|
|
|
Main *bmain = CTX_data_main(BPy_GetContext());
|
|
|
|
Main *mainl = NULL;
|
|
|
|
int err = 0;
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
2016-02-15 19:35:35 +01:00
|
|
|
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
|
|
|
/* here appending/linking starts */
|
2015-10-12 13:46:58 +02:00
|
|
|
mainl = BLO_library_link_begin(bmain, &(self->blo_handle), self->relpath);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
|
|
|
{
|
2013-03-25 02:41:30 +00:00
|
|
|
int idcode_step = 0, idcode;
|
|
|
|
while ((idcode = BKE_idcode_iter_step(&idcode_step))) {
|
|
|
|
if (BKE_idcode_is_linkable(idcode)) {
|
|
|
|
const char *name_plural = BKE_idcode_to_name_plural(idcode);
|
2011-12-26 12:26:11 +00:00
|
|
|
PyObject *ls = PyDict_GetItemString(self->dict, name_plural);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
// printf("lib: %s\n", name_plural);
|
2011-10-13 01:29:08 +00:00
|
|
|
if (ls && PyList_Check(ls)) {
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
/* loop */
|
2011-12-26 12:26:11 +00:00
|
|
|
Py_ssize_t size = PyList_GET_SIZE(ls);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
Py_ssize_t i;
|
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
for (i = 0; i < size; i++) {
|
2016-07-14 17:38:22 +10:00
|
|
|
PyObject *item_src = PyList_GET_ITEM(ls, i);
|
2016-07-14 21:00:05 +10:00
|
|
|
PyObject *item_dst; /* must be set below */
|
2016-07-14 17:38:22 +10:00
|
|
|
const char *item_idname = _PyUnicode_AsString(item_src);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
2016-07-14 17:38:22 +10:00
|
|
|
// printf(" %s\n", item_idname);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
2016-07-14 17:38:22 +10:00
|
|
|
if (item_idname) {
|
|
|
|
ID *id = BLO_library_link_named_part(mainl, &(self->blo_handle), idcode, item_idname);
|
2011-10-13 01:29:08 +00:00
|
|
|
if (id) {
|
2011-05-24 15:21:14 +00:00
|
|
|
#ifdef USE_RNA_DATABLOCKS
|
2014-01-31 00:53:02 +11:00
|
|
|
/* swap name for pointer to the id */
|
2016-07-14 17:38:22 +10:00
|
|
|
item_dst = PyCapsule_New((void *)id, NULL, NULL);
|
2016-07-14 21:00:05 +10:00
|
|
|
#else
|
|
|
|
/* leave as is */
|
|
|
|
continue;
|
2011-05-24 15:21:14 +00:00
|
|
|
#endif
|
2011-03-13 01:15:14 +00:00
|
|
|
}
|
2011-05-24 15:21:14 +00:00
|
|
|
else {
|
2016-07-14 17:38:22 +10:00
|
|
|
bpy_lib_exit_warn_idname(self, name_plural, item_idname);
|
2011-05-24 15:21:14 +00:00
|
|
|
/* just warn for now */
|
|
|
|
/* err = -1; */
|
2016-07-14 17:38:22 +10:00
|
|
|
item_dst = Py_INCREF_RET(Py_None);
|
2011-05-24 15:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ID or None */
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* XXX, could complain about this */
|
2016-07-14 17:38:22 +10:00
|
|
|
bpy_lib_exit_warn_type(self, item_src);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
PyErr_Clear();
|
2016-07-14 17:38:22 +10:00
|
|
|
item_dst = Py_INCREF_RET(Py_None);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
}
|
2011-05-24 15:21:14 +00:00
|
|
|
|
2016-07-14 21:00:05 +10:00
|
|
|
/* item_dst must be new or already incref'd */
|
|
|
|
Py_DECREF(item_src);
|
|
|
|
PyList_SET_ITEM(ls, i, item_dst);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (err == -1) {
|
2011-03-13 01:15:14 +00:00
|
|
|
/* exception raised above, XXX, this leaks some memory */
|
|
|
|
BLO_blendhandle_close(self->blo_handle);
|
2011-12-26 12:26:11 +00:00
|
|
|
self->blo_handle = NULL;
|
2016-02-15 19:35:35 +01:00
|
|
|
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
|
2011-03-13 01:15:14 +00:00
|
|
|
return NULL;
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
}
|
2011-03-13 01:15:14 +00:00
|
|
|
else {
|
2011-12-26 12:26:11 +00:00
|
|
|
Library *lib = mainl->curlib; /* newly added lib, assign before append end */
|
2015-10-12 15:07:07 +02:00
|
|
|
BLO_library_link_end(mainl, &(self->blo_handle), self->flag, NULL, NULL);
|
2011-03-13 01:15:14 +00:00
|
|
|
BLO_blendhandle_close(self->blo_handle);
|
2011-12-26 12:26:11 +00:00
|
|
|
self->blo_handle = NULL;
|
2011-03-13 01:15:14 +00:00
|
|
|
|
2012-03-26 20:41:54 +00:00
|
|
|
/* copied from wm_operator.c */
|
|
|
|
{
|
2011-03-13 01:15:14 +00:00
|
|
|
/* mark all library linked objects to be updated */
|
2016-07-14 21:00:05 +10:00
|
|
|
BKE_main_lib_objects_recalc_all(bmain);
|
2011-03-13 01:15:14 +00:00
|
|
|
|
|
|
|
/* append, rather than linking */
|
2011-12-26 12:26:11 +00:00
|
|
|
if ((self->flag & FILE_LINK) == 0) {
|
2016-01-04 14:02:05 +01:00
|
|
|
BKE_library_make_local(bmain, lib, true, false);
|
2011-03-13 01:15:14 +00:00
|
|
|
}
|
|
|
|
}
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
2016-02-15 19:35:35 +01:00
|
|
|
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
|
2014-01-31 00:53:02 +11:00
|
|
|
/* finally swap the capsules for real bpy objects
|
|
|
|
* important since BLO_library_append_end initializes NodeTree types used by srna->refine */
|
2016-07-14 21:00:05 +10:00
|
|
|
#ifdef USE_RNA_DATABLOCKS
|
2014-01-31 00:53:02 +11:00
|
|
|
{
|
|
|
|
int idcode_step = 0, idcode;
|
|
|
|
while ((idcode = BKE_idcode_iter_step(&idcode_step))) {
|
|
|
|
if (BKE_idcode_is_linkable(idcode)) {
|
|
|
|
const char *name_plural = BKE_idcode_to_name_plural(idcode);
|
|
|
|
PyObject *ls = PyDict_GetItemString(self->dict, name_plural);
|
|
|
|
if (ls && PyList_Check(ls)) {
|
|
|
|
Py_ssize_t size = PyList_GET_SIZE(ls);
|
|
|
|
Py_ssize_t i;
|
|
|
|
PyObject *item;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
item = PyList_GET_ITEM(ls, i);
|
|
|
|
if (PyCapsule_CheckExact(item)) {
|
|
|
|
PointerRNA id_ptr;
|
|
|
|
ID *id;
|
|
|
|
|
|
|
|
id = PyCapsule_GetPointer(item, NULL);
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
|
|
|
RNA_id_pointer_create(id, &id_ptr);
|
|
|
|
item = pyrna_struct_CreatePyObject(&id_ptr);
|
|
|
|
PyList_SET_ITEM(ls, i, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-14 21:00:05 +10:00
|
|
|
#endif /* USE_RNA_DATABLOCKS */
|
2014-01-31 00:53:02 +11:00
|
|
|
|
2011-03-13 01:15:14 +00:00
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
}
|
|
|
|
|
2011-03-14 01:00:41 +00:00
|
|
|
static PyObject *bpy_lib_dir(BPy_Library *self)
|
|
|
|
{
|
|
|
|
return PyDict_Keys(self->dict);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-03 13:11:07 +11:00
|
|
|
int BPY_library_load_module(PyObject *mod_par)
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
{
|
2016-03-03 13:11:07 +11:00
|
|
|
static PyMethodDef load_meth = {
|
|
|
|
"load", (PyCFunction)bpy_lib_load,
|
|
|
|
METH_STATIC | METH_VARARGS | METH_KEYWORDS,
|
|
|
|
bpy_lib_load_doc,
|
|
|
|
};
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
PyModule_AddObject(mod_par, "_library_load", PyCFunction_New(&load_meth, NULL));
|
|
|
|
|
2012-03-18 07:38:51 +00:00
|
|
|
/* some compilers don't like accessing this directly, delay assignment */
|
2011-12-26 12:26:11 +00:00
|
|
|
bpy_lib_Type.tp_getattro = PyObject_GenericGetAttr;
|
2011-03-15 01:48:01 +00:00
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (PyType_Ready(&bpy_lib_Type) < 0)
|
library loading api.
this is not well suited to RNA so this is a native python api.
This uses:
bpy.data.libraries.load(filepath, link=False, relative=False)
however the return value needs to use pythons context manager, this means the library loading is confined to a block of code and python cant leave a half loaded library state.
eg, load a single scene we know the name of:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = ["Scene"]
eg, load all scenes:
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.scenes = data_from.scenes
eg, load all objects starting with 'A'
with bpy.data.libraries.load(filepath) as (data_from, data_to):
data_to.objects = [name for name in data_from.objects if name.startswith("A")]
As you can see gives 2 objects like 'bpy.data', but containing lists of strings which can be moved from one into another.
2011-03-12 16:06:37 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|