[Bf-python] Adding a new way to deal with libraries

Campbell Barton cbarton at metavr.com
Tue Mar 13 08:20:10 CET 2007


comments inline

Ken Hughes wrote:
> Campbell Barton wrote:
> 
>> in regards to bpy.libraries
>>
>> typedef struct {
>>     PyObject_VAR_HEAD /* required python macro */
>>     char filename[FILE_MAXDIR + FILE_MAXFILE]
>> } BPy_Lib;
>>
>> a library wouldnt be linked to anything, just a filename...
>>
>> so "for lib in bpy.libraries" - would only return a list or iterator 
>> of of open libraries, as you point out, its not THAT usefull...
> 
> So it's just a placeholder for the filename and some methods to link or 
> append data from those files.  Which also means .load() is misleading; 
> we could just as well say "lib = bpy.library.define('//file.blend')" or 
> something.

This could be the case, however it could also load it just as 
Blender.Library.Open does.. would need to implement this to know whats 
best..

I think .load() is still better then .define(), weather the actual 
loading is delayed or not, the library is still bing loaded.


I thaught of doing..
lib = bpy.libraries['//some_new_lib.blend']

but that infers '//some_new_lib.blend' is alredy a part of bpy.libraries


>>> When dealing with libs, the Python API would have to deal with loading 
>> and unloading the blend files, this would be done whenever the 
>> lib-data was accessed. so the user removing a file is ok. just return 
>> an error next time its accessed.
>>
>> a BPy_Lib isnt realy linked into bpy.libraries, so new bpy.libraries 
>> could be created..
>>
>> lib = bpy.libraries.load('//mylib.blend')
>>
>> then the scripter could load some data from the lib, and it would then 
>> become a part of bpy.libraries
> 
> "become a part of"... do you mean "bpy.libraries.materials" could now be 
> used to access the materials in a library we load?

lib = bpy.libraries.load('//mylib.blend')

'//mylib.blend' would not become a lib in bpy.libraries.. since it has 
no users. only when data was loaded from it would it appier in 
bpy.libraries.



Im not thinking we'd have bpy.libraries.materials

if its a list then
bpy.libraries[-1].materials


example of how it might work.
____

len(bpy.libraries) == 0

lib = bpy.libraries.load('//mylib.blend')
mat = lib.materials.link('someMat') # loading could be delayed until now

len(bpy.libraries) == 1

> 
>> lib filenames should also be writable..
>>
>> lib.filename = '//....' - this would inspect blender for a name 
>> matching  "lib" and rename its filename to the assigned one..
> 
> Don't get this.  Can you give a better example?


changing the name of a lib isnt uncommon, the outliner can do it even 
and Iv heard before that, with project orange they used binary editor.

say you want to make all the library names absolute paths..

for lib in bpy.libraries:
     lib.filename = sys.expandpath(lib.filename)





More information about the Bf-python mailing list