BlendDataLibraries(bpy_struct)

base class — bpy_struct

class bpy.types.BlendDataLibraries.BlendDataLibraries(bpy_struct)

Collection of libraries

tag(value)

tag

Parameters

value (boolean) – Value

remove(library, do_unlink=True, do_id_user=True, do_ui_user=True)

Remove a camera from the current blendfile

Parameters
  • library (Library, (never None)) – Library to remove

  • do_unlink (boolean, (optional)) – Unlink all usages of this library before deleting it

  • do_id_user (boolean, (optional)) – Decrement user counter of all datablocks used by this object

  • do_ui_user (boolean, (optional)) – Make sure interface does not reference this object

classmethod bl_rna_get_subclass(id, default=None)
Parameters

id (string) – The RNA type identifier.

Returns

The RNA type or default when not found.

Return type

bpy.types.Struct subclass

classmethod bl_rna_get_subclass_py(id, default=None)
Parameters

id (string) – The RNA type identifier.

Returns

The class or default when not found.

Return type

type

load(filepath, link=False, relative=False)

Returns a context manager which exposes 2 library objects on entering. Each object has attributes matching bpy.data which are lists of strings to be linked.

Parameters
  • filepath (string) – The path to a blend file.

  • link (bool) – When False reference to the original file is lost.

  • relative (bool) – When True the path is stored relative to the open blend file.

import bpy

filepath = "//link_library.blend"

# load a single scene we know the name of.
with bpy.data.libraries.load(filepath) as (data_from, data_to):
    data_to.scenes = ["Scene"]


# load all meshes
with bpy.data.libraries.load(filepath) as (data_from, data_to):
    data_to.meshes = data_from.meshes


# link all objects starting with 'A'
with bpy.data.libraries.load(filepath, link=True) as (data_from, data_to):
    data_to.objects = [name for name in data_from.objects if name.startswith("A")]


# append everything
with bpy.data.libraries.load(filepath) as (data_from, data_to):
    for attr in dir(data_to):
        setattr(data_to, attr, getattr(data_from, attr))


# the loaded objects can be accessed from 'data_to' outside of the context
# since loading the data replaces the strings for the datablocks or None
# if the datablock could not be loaded.
with bpy.data.libraries.load(filepath) as (data_from, data_to):
    data_to.meshes = data_from.meshes
# now operate directly on the loaded data
for mesh in data_to.meshes:
    if mesh is not None:
        print(mesh.name)
write(filepath, datablocks, path_remap=False, fake_user=False, compress=False)

Write data-blocks into a blend file.

Note

Indirectly referenced data-blocks will be expanded and written too.

Parameters
  • filepath (string) – The path to write the blend-file.

  • datablocks (set) – set of data-blocks (bpy.types.ID instances).

  • path_remap (string) –

    Optionally remap paths when writing the file:

    • NONE No path manipulation (default).

    • RELATIVE Remap paths that are already relative to the new location.

    • RELATIVE_ALL Remap all paths to be relative to the new location.

    • ABSOLUTE Make all paths absolute on writing.

  • fake_user (bool) – When True, data-blocks will be written with fake-user flag enabled.

  • compress (bool) – When True, write a compressed blend file.

import bpy

filepath = "//new_library.blend"

# write selected objects and their data to a blend file
data_blocks = set(bpy.context.selected_objects)
bpy.data.libraries.write(filepath, data_blocks)


# write all meshes starting with a capital letter and
# set them with fake-user enabled so they aren't lost on re-saving
data_blocks = {mesh for mesh in bpy.data.meshes if mesh.name[:1].isupper()}
bpy.data.libraries.write(filepath, data_blocks, fake_user=True)


# write all materials, textures and node groups to a library
data_blocks = {*bpy.data.materials, *bpy.data.textures, *bpy.data.node_groups}
bpy.data.libraries.write(filepath, data_blocks)

Inherited Properties

  • bpy_struct.id_data

Inherited Functions

  • bpy_struct.as_pointer

  • bpy_struct.driver_add

  • bpy_struct.driver_remove

  • bpy_struct.get

  • bpy_struct.is_property_hidden

  • bpy_struct.is_property_overridable_library

  • bpy_struct.is_property_readonly

  • bpy_struct.is_property_set

  • bpy_struct.items

  • bpy_struct.keyframe_delete

  • bpy_struct.keyframe_insert

  • bpy_struct.keys

  • bpy_struct.path_from_id

  • bpy_struct.path_resolve

  • bpy_struct.pop

  • bpy_struct.property_overridable_library_set

  • bpy_struct.property_unset

  • bpy_struct.type_recast

  • bpy_struct.values

References

  • BlendData.libraries