Blender V4.3
bpy_library_load.cc File Reference
#include <Python.h>
#include <cstddef>
#include "BLI_linklist.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "BKE_blendfile_link_append.hh"
#include "BKE_context.hh"
#include "BKE_idtype.hh"
#include "BKE_lib_id.hh"
#include "BKE_main.hh"
#include "BKE_report.hh"
#include "DNA_space_types.h"
#include "BLO_readfile.hh"
#include "MEM_guardedalloc.h"
#include "bpy_capi_utils.hh"
#include "bpy_library.hh"
#include "../generic/py_capi_utils.hh"
#include "../generic/python_compat.hh"
#include "../generic/python_utildefines.hh"
#include "RNA_access.hh"
#include "bpy_rna.hh"

Go to the source code of this file.

Classes

struct  BPy_Library
 
struct  LibExitLappContextItemsIterData
 

Macros

#define USE_RNA_DATABLOCKS
 

Functions

static PyObject * bpy_lib_load (BPy_PropertyRNA *self, PyObject *args, PyObject *kw)
 
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)
 
static void bpy_lib_dealloc (BPy_Library *self)
 
 PyDoc_STRVAR (bpy_lib_load_doc, ".. method:: load(" "filepath, " "link=False, " "relative=False, " "assets_only=False, " "create_liboverrides=False, " "reuse_liboverrides=False, " "create_liboverrides_runtime=False)\n" "\n" " Returns a context manager which exposes 2 library objects on entering.\n" " Each object has attributes matching bpy.data which are lists of strings to be linked.\n" "\n" " :arg filepath: The path to a blend file.\n" " :type filepath: str | bytes\n" " :arg link: When False reference to the original file is lost.\n" " :type link: bool\n" " :arg relative: When True the path is stored relative to the open blend file.\n" " :type relative: bool\n" " :arg assets_only: If True, only list data-blocks marked as assets.\n" " :type assets_only: bool\n" " :arg create_liboverrides: If True and ``link`` is True, liboverrides will\n" " be created for linked data.\n" " :type create_liboverrides: bool\n" " :arg reuse_liboverrides: If True and ``create_liboverride`` is True,\n" " search for existing liboverride first.\n" " :type reuse_liboverrides: bool\n" " :arg create_liboverrides_runtime: If True and ``create_liboverride`` is True,\n" " create (or search for existing) runtime liboverride.\n" " :type create_liboverrides_runtime: bool\n")
 
static PyObject * _bpy_names (BPy_Library *self, int blocktype)
 
static void bpy_lib_exit_warn_idname (BPy_Library *self, const char *name_plural, const char *idname)
 
static void bpy_lib_exit_warn_type (BPy_Library *self, PyObject *item)
 
static bool bpy_lib_exit_lapp_context_items_cb (BlendfileLinkAppendContext *lapp_context, BlendfileLinkAppendContextItem *item, LibExitLappContextItemsIterData &data)
 
int BPY_library_load_type_ready ()
 

Variables

static PyMethodDef bpy_lib_methods []
 
static PyTypeObject bpy_lib_Type
 
PyMethodDef BPY_library_load_method_def
 

Detailed Description

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 Python's context manager (__enter__ and __exit__).

Everything here is exposed via bpy.data.libraries.load(...) which returns a context manager.

Definition in file bpy_library_load.cc.

Macro Definition Documentation

◆ USE_RNA_DATABLOCKS

#define USE_RNA_DATABLOCKS

Definition at line 45 of file bpy_library_load.cc.

Function Documentation

◆ _bpy_names()

static PyObject * _bpy_names ( BPy_Library * self,
int blocktype )
static

◆ bpy_lib_dealloc()

static void bpy_lib_dealloc ( BPy_Library * self)
static

Definition at line 95 of file bpy_library_load.cc.

References self.

◆ bpy_lib_dir()

static PyObject * bpy_lib_dir ( BPy_Library * self)
static

Definition at line 586 of file bpy_library_load.cc.

References self.

◆ bpy_lib_enter()

◆ bpy_lib_exit()

◆ bpy_lib_exit_lapp_context_items_cb()

◆ bpy_lib_exit_warn_idname()

static void bpy_lib_exit_warn_idname ( BPy_Library * self,
const char * name_plural,
const char * idname )
static

Definition at line 362 of file bpy_library_load.cc.

References self.

Referenced by bpy_lib_exit_lapp_context_items_cb().

◆ bpy_lib_exit_warn_type()

static void bpy_lib_exit_warn_type ( BPy_Library * self,
PyObject * item )
static

Definition at line 383 of file bpy_library_load.cc.

References self.

Referenced by bpy_lib_exit().

◆ bpy_lib_load()

◆ BPY_library_load_type_ready()

int BPY_library_load_type_ready ( )

Definition at line 607 of file bpy_library_load.cc.

References bpy_lib_Type.

Referenced by BPy_init_modules().

◆ PyDoc_STRVAR()

PyDoc_STRVAR ( bpy_lib_load_doc ,
".. method:: load(" "filepath, " "link=False, " "relative=False, " "assets_only=False, " "create_liboverrides=False, " "reuse_liboverrides=False, " "create_liboverrides_runtime=False)\n" "\n" " Returns a context manager which exposes 2 library objects on entering.\n" " Each object has attributes matching bpy.data which are lists of strings to be linked.\n" "\n" " :arg filepath: The path to a blend file.\n" " :type filepath: str | bytes\n" " :arg link: When False reference to the original file is lost.\n" " :type link: bool\n" " :arg relative: When True the path is stored relative to the open blend file.\n" " :type relative: bool\n" " :arg assets_only: If True,
only list data-blocks marked as assets.\n" " :type assets_only:bool\n" " :arg create_liboverrides:If True and ``link`` is True,
liboverrides will\n" " be created for linked data.\n" " :type create_liboverrides:bool\n" " :arg reuse_liboverrides:If True and ``create_liboverride`` is True,
\n" " search for existing liboverride first.\n" " :type reuse_liboverrides:bool\n" " :arg create_liboverrides_runtime:If True and ``create_liboverride`` is True,
\n" " create(or search for existing) runtime liboverride.\n" " :type create_liboverrides_runtime:bool\n"  )

Variable Documentation

◆ bpy_lib_methods

PyMethodDef bpy_lib_methods[]
static
Initial value:
= {
{"__enter__", (PyCFunction)bpy_lib_enter, METH_NOARGS},
{"__exit__", (PyCFunction)bpy_lib_exit, METH_VARARGS},
{"__dir__", (PyCFunction)bpy_lib_dir, METH_NOARGS},
{nullptr}
}
static PyObject * bpy_lib_exit(BPy_Library *self, PyObject *args)
static PyObject * bpy_lib_enter(BPy_Library *self)
static PyObject * bpy_lib_dir(BPy_Library *self)

Definition at line 84 of file bpy_library_load.cc.

◆ bpy_lib_Type

PyTypeObject bpy_lib_Type
static

Definition at line 101 of file bpy_library_load.cc.

Referenced by bpy_lib_enter(), bpy_lib_load(), and BPY_library_load_type_ready().

◆ BPY_library_load_method_def

PyMethodDef BPY_library_load_method_def
Initial value:
= {
"load",
(PyCFunction)bpy_lib_load,
METH_VARARGS | METH_KEYWORDS,
bpy_lib_load_doc,
}
static PyObject * bpy_lib_load(BPy_PropertyRNA *self, PyObject *args, PyObject *kw)

Definition at line 596 of file bpy_library_load.cc.

Referenced by BPY_rna_types_extend_capi().