Module Library

Module Library

source code

The Blender.Library submodule.

Library

This module provides access to objects stored in .blend files. With it scripts can append from Blender files to the current scene, like the File->Append menu entry in Blender does. It allows programmers to use .blend files as data files for their scripts.


Warning:

This module is being considered for deprecation. Users should consider using the new Library module and stay tuned to see which module is supported in the end.

Example:
 import Blender
 from Blender import Library

 def f(name):
   open_library(name)

 def open_library(name):
   Library.Open(name)
   groups = Library.LinkableGroups()

   for db in groups:
     print "DATABLOCK %s:" % db
     for obname in Library.Datablocks(db):
       print obname

   if 'Object' in groups:
     for obname in Library.Datablocks('Object'):
       Library.Load(obname, 'Object', 0) # note the 0...
     Library.Update()

   Library.Close()
   b.Redraw()

 b.Window.FileSelector(f, "Choose Library", "*.blend")

Functions
bool
Open(filename)
Open an existing .blend file.
source code
 
Close()
Close the currently open library file, if any.
source code
string
getName()
Get the filename of the currently open library file.
source code
list of strings
LinkableGroups()
Get all the linkable group names from the currently open library file.
source code
 
Datablocks(group)
Get all datablock objects of the given 'group' available in the currently open library file.
source code
 
Load(datablock, group, update=1, linked=0)
Load the given datablock object from the current library file
source code
 
Update()
Update all links and display lists in Blender.
source code
Function Details

Open(filename)

source code 
Open an existing .blend file. If there was already one open file, it is closed first.
Parameters:
  • filename (string) - The filename of a Blender file. Filenames starting with "//" will be loaded relative to the blend file's location.
Returns: bool
1 if successful. An IOError exception is thrown if the file cannot be opened.

getName()

source code 
Get the filename of the currently open library file.
Returns: string
The open library filename.

LinkableGroups()

source code 
Get all the linkable group names from the currently open library file. These are the available groups for linking with the current scene. Ex: 'Object', 'Mesh', 'Material', 'Text', etc.
Returns: list of strings
the list of linkable groups.

Datablocks(group)

source code 
Get all datablock objects of the given 'group' available in the currently open library file.
Parameters:

Load(datablock, group, update=1, linked=0)

source code 
Load the given datablock object from the current library file
Parameters:
  • datablock (string) - an available object name, as returned by Datablocks.
  • group (string) - an available group name, as returned by LinkableGroups.
  • update (bool) - defines if Blender should be updated after loading this object. This means linking all objects and remaking all display lists, so it is potentially very slow.
  • linked (bool) - Will keep objects linked to their source blend file, the update option or later updating will unlink the data from the original blend and make it local.

Warning: If you plan to load more than one object in sequence, it is definitely recommended to set 'update' to 0 in all calls to this function and after them call Update.

Update()

source code 
Update all links and display lists in Blender. This function should be called after a series of Load(datablock, group, 0) calls to make everything behave nicely.

Warning: to use this function, remember to set the third Load parameter to zero or each loading will automatically update Blender, which will slow down your script and make you look like a lousy programmer. Enough warnings :)?